フィルターのクリア

fclose error "Not enough input arguments"

1 回表示 (過去 30 日間)
Ryan
Ryan 2011 年 7 月 18 日
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?

採用された回答

Jan
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 件のコメント
Ryan
Ryan 2011 年 7 月 18 日
Thanks, heh, I actually figured this out about 10 seconds after I posted my question. It's always the dumb little things like that ...

サインインしてコメントする。

その他の回答 (1 件)

Friedrich
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.
  1 件のコメント
Ryan
Ryan 2011 年 7 月 18 日
Yeah, that was a typo. Good catch.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by