fclose error "Not enough input arguments"
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Jan
2011-7-18
"fclose(all)" calls the function all, but you want:
fclose('all')
which is equivalent to:
fclose all
For exactly such cases it is stated so often in this forum, that the complete error message should be (read and) posted:
??? Error using ==> all
Not enough input arguments.
更多回答(1 个)
Friedrich
2011-7-18
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!