fclose error "Not enough input arguments"
Afficher commentaires plus anciens
I have an .m file that saves the data output from a program into two different text files. The code is as follows:
if isempty (myfile)
myfile = ['Data_' num2str(nsub) '.txt'];
end
% fileout = ([cd, '\', myfile]);
fileout = myfile;
if isempty(nsub)
namesubj = 'thresholds.txt';
else
namesubj = ['Thresholds_' num2str(nsub) '.txt'];
end
filesubj = fopen(namesubj, 'a');
fprintf (filesubj, 'BLOCK\tTHRESHOLD\n');
if exist(fileout, 'file');
fprintf (fileout, 'nsub\tblock\ttrial\tlevel\tgamma\trispAC\tthreshold\n');
for i=1:size(MATSAVEDATA,1)
fprintf(fileout, '%3.0f\t%s\t%s\t%2.0f\t%2.0f\t%4.3f\t%1.1f\t%1.0f\
t%4.3f\t%s\n', nsub, ... %%I TOOK OUT THE REST OF THIS FUNCTION JUST BECAUSE IT IS EXTREMELY LONG AND SCREWS UP THE FORMATTING)
if i<size(MATSAVEDATA,1)&& MATSAVEDATA (i+1,1)~= MATSAVEDATA (i,1)||
i==size(MATSAVEDATA,1)
fprintf (filesubj,'%2.0f\t%3.3f\n',MATSAVEDATA (i,1),MATSAVEDATA (i,6));
end
end
end
fclose (all);
Now, the problem I have is with fclose. When I run the program it gives me the error "Not enough input arguments." I tried changing the end to:
fclose (fileout);
fclose (filesubj);
But MATLAB gave me an error that said I needed to use fclose (all). I don't understand what the issue is here, fclose (all) should just close both of the files, what does it mean that there aren't enough input arguments?
Réponse acceptée
Plus de réponses (1)
Friedrich
le 18 Juil 2011
Hi,
e.g. this call
fprintf (fileout, 'nsub\tblock\ttrial\tlevel\tgamma\trispAC\tthreshold\n');
is not correct since fprintf expects a file pointer and not a file name. I think this is just a little typo since you are checking for the existence of that file one line higher. Change it to filesubj and the fclose to fclose(filesubj) should solve the issue.
1 commentaire
Ryan
le 18 Juil 2011
Catégories
En savoir plus sur Variables 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!