Invalid permission error with fopen()

5 Ansichten (letzte 30 Tage)
DONGUK KIM
DONGUK KIM am 28 Mai 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

Antworten (1)

Bhargavi Maganuru
Bhargavi Maganuru am 7 Jul. 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

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by