fclose error "Not enough input arguments"

2 visualizaciones (últimos 30 días)
Ryan
Ryan el 18 de Jul. de 2011
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?

Respuesta aceptada

Jan
Jan el 18 de Jul. de 2011
"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 comentario
Ryan
Ryan el 18 de Jul. de 2011
Thanks, heh, I actually figured this out about 10 seconds after I posted my question. It's always the dumb little things like that ...

Iniciar sesión para comentar.

Más respuestas (1)

Friedrich
Friedrich el 18 de Jul. de 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.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by