Azzera filtri
Azzera filtri

Invalid permission error with fopen()

5 visualizzazioni (ultimi 30 giorni)
DONGUK KIM
DONGUK KIM il 28 Mag 2020
for i = 1:30
fid = fopen('%d.asc', i, 'r');
C = textscan(fid, '%s%s', 'Delimiter',',', 'HeaderLines', 1);
for k = 1:1046
E(k,1) = E(k,1) + str2double(string(C{1,1}(k,1)));
E(k,2) = E(k,2) + str2double(string(C{1,2}(k,1)));
end
fclose(fid);
end
E = (1/30) * E;
E
The code worked fine with reading just one file but it started giving permission errors when I put it in a loop.
The exact error message was :
Error using fopen
Invalid permission.
Error in physexp1 (line 2)
fid = fopen('%d.asc', i, 'r');
How would I fix this?
Thanks

Risposte (1)

Bhargavi Maganuru
Bhargavi Maganuru il 7 Lug 2020
Hi,
It might be an unappropriate way to format string using specifiers inside fopen. Instead you can try specifying filename seperately inside for loop and give that as input to fopen.
for i = 1:30
filename = sprintf('%d.asc', i);
fid = fopen(filename, 'r');
fclose(fid);
end

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by