??? Error using ==> fprintf Invalid file identifier. Use fopen to generate a valid file identifier.
Mostrar comentarios más antiguos
Hi, I get this error when running a statistical analysis. Can anyone help me with that? I always used this script and always worked. I have just moved to a group license and everything stopped working. I am using Matlab 2010a (MAC OSX 64-bit). Many thanks. Here is the code:
for cd = 1:NSTIM,
fid = fopen([pwd '/' directory '/Stats_' vec_info(cd).evmarker],'w');
fprintf(fid,'%s\n',[' HbO_2 HHb ']);
fprintf(fid,'%s',['Channel P-val H-val PosMchge Mchange Ntrials']);
fprintf(fid,'%s\n',[' P-val H-val PosMchge Mchange Ntrials']);
for ch = 1:NTRACES,
fprintf(fid,'%6f %6.8f %6f %6.8f %6.8f %6f ',ch, Pval_STIM_oxy(cd,ch),Hval_STIM_oxy(cd,ch),pos_oxy(ch),mean_oxy(ch,cd),Ntrials_oxy(ch,cd));
fprintf(fid,'%6.8f %6f %6.8f %6.8f %6f\n',Pval_STIM_deoxy(cd,ch),Hval_STIM_deoxy(cd,ch),pos_deoxy(ch),mean_deoxy(ch,cd),Ntrials_deoxy(ch,cd));
end
fclose(fid);
Respuestas (2)
per isakson
el 3 de Oct. de 2012
Editada: per isakson
el 3 de Oct. de 2012
0 votos
- legal file name? what string is produced by "[pwd '/' directory '/Stats_' vec_info(cd).evmarker]"?
- add assert( fid >= 3, ... ) to the code
- use [ fid, message] = fopen( filename, ...) and output message with the the message of assert
2 comentarios
Maria
el 3 de Oct. de 2012
Walter Roberson
el 3 de Oct. de 2012
You currently have
fid = fopen( [etc]
change that to
[fid, message] = fopen( [etc]
Obviously this line fails:
fid = fopen([pwd '/' directory '/Stats_' vec_info(cd).evmarker],'w');
You could and should catch corresponding problems using:
[fid, msg] = fopen(fullfile(pwd, directory, ['Stats_', vec_info(cd).evmarker], 'w');
if fid == -1
error(msg);
end
I guess, that either the file is existing already and write-protected, or you do not have write permissions to the folder.
FULLFILE considers trailing file separators, e.g. if the current directory is "C:\".
2 comentarios
muqeet ahmad +8613730636065
el 26 de Ag. de 2017
Editada: Walter Roberson
el 26 de Ag. de 2017
[fid, msg] = fopen(fullfile(pwd, directory, ['Stats_', vec_info(cd).evmarker], 'w'); if fid == -1 error(msg); end
what if i want to change the directory of file, is it possible?
Walter Roberson
el 26 de Ag. de 2017
Remove the pwd and set the variable named directory to whatever directory name you want to write to
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!