fprintf use with error
Mostrar comentarios más antiguos
Hi,
I am getting warning with fprintf function in my script as specify below, I reallly don't how to figure out. I am a new matlab user
Thanks for your help
fprintf(fileID, " pointList.append(eval('(%s)' %line.strip())))\n");
error / warning : The format might not agree with the argument count
Respuesta aceptada
Más respuestas (2)
Fangjun Jiang
el 4 de Ag. de 2022
Editada: Fangjun Jiang
el 4 de Ag. de 2022
use single quote mark, not double quote mark
a=1.2;
fid=1
fprintf(fid, 'this is my number %f', a)
1 comentario
Rigo ZOO
el 4 de Ag. de 2022
Image Analyst
el 4 de Ag. de 2022
The problem is you're using %s but not passing in any string after the format string. It needs to be of this form
fprintf(fid, 'stuff blah blah %s more stuff.\n', yourString);
The fprintf is seeing %s but not seeing yourString. Essentially you have
fprintf(fileID, " stuff %s more stuff\n");
as far as the mlint syntax checker is concerned. What is really wants to see is
fprintf(fileID, " stuff %s more stuff\n", yourString);
What you should do is this:
% Evaluate the expression with the hated eval
someNumber = eval(someString);
% Say someNumber is 5 and you'll use that as an index to the pointList.append array
yourString = sprintf(' pointList.append(eval(%d) %%line.strip())))\n', someNumber)
% Now write that string to the file.
fprintf(fileID, "%s\n", yourString);
1 comentario
Rigo ZOO
el 4 de Ag. de 2022
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!