fprintf: Function is not defined for 'cell' inputs.
Mostrar comentarios más antiguos
Can someone say what is wrong with my code?
the errors are: *??? Error using ==> fprintf Function is not defined for 'cell' inputs.
Error in ==> TESTAR at 37 fprintf('Problem statement:\n%s', problem_statement);*
my code is:
clear; run('..\psg_load_libraries'); addpath('..');
clear problem_statement;
problem_statement(1)= textread('problem_DEA_Hospital.txt','%s', 'whitespace', ''); problem_statement(2)= textread('problem_DEA_Hospital2.txt','%s', 'whitespace', '');
% read and print problem statement
for i=1:1:2
problem_statement=problem_statement(i);
fprintf('Problem statement:\n%s', problem_statement);
end
Respuesta aceptada
Más respuestas (1)
It sounds like "problem_statement" is a cell array, and fprintf cannot accept cells as arguments. What if you change the second to last line to this:
problem_statement=problem_statement{i};
That will cause your new definition of "problem_statement" to access the contents of the ith cell of the problem_statement cell array instead of the ith cell itself.
Note, though, that I don't think the second iteration of your code will run correctly if you're redefining problem_statement as a single-element array before trying to later access the second element. You might want to give problem_statement a different name in the loop instead of redefining it.
Categorías
Más información sobre Variables en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!