Borrar filtros
Borrar filtros

Invalid permission error with fopen()

10 visualizaciones (últimos 30 días)
DONGUK KIM
DONGUK KIM el 7 de Jun. de 2020
Respondida: Pulkit Goel el 8 de Jun. de 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

Respuestas (1)

Pulkit Goel
Pulkit Goel el 8 de Jun. de 2020
Saving file name in a variable worked for me. Try running the following code:
for i = 1:30
name=string(i)+'.asc';
fid = fopen(name, '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
I guess creating the name of file in fopen is causing the problem.

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by