??? Error using ==> fprintf Invalid file identifier. Use fopen to generate a valid file identifier.
Afficher commentaires plus anciens
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);
Réponses (2)
per isakson
le 3 Oct 2012
Modifié(e) : per isakson
le 3 Oct 2012
0 votes
- 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 commentaires
Maria
le 3 Oct 2012
Walter Roberson
le 3 Oct 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 commentaires
muqeet ahmad +8613730636065
le 26 Août 2017
Modifié(e) : Walter Roberson
le 26 Août 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
le 26 Août 2017
Remove the pwd and set the variable named directory to whatever directory name you want to write to
Catégories
En savoir plus sur R Language dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!