Really! fprintf cell error
Afficher commentaires plus anciens
function []=printresults2file(shape)
fid=fopen('ChangyuLiu.txt','wt');
fprintf(fid, 'The number of entered objects was %d \n', size(shape,1));
fprintf(fid,'%s \t\t %s \t\t %s \t\t %s\n','No.','ID','Color','Area');
for i=1:size(shape,1)
fprintf(fid, '%d %s %s %f',shape{i,:});
fprintf('\n');
end
fclose(fid);
end
This is a sub-function I used to output a table in .txt file. However, the error kept pumping up as
Error using fprintf
Function is not defined for 'cell' inputs.
I wonder what's causing the problem.
6 commentaires
James Tursa
le 2 Avr 2020
Modifié(e) : James Tursa
le 2 Avr 2020
What is in shape, specifically what does shape{i,:} produce?
Also, is fprintf('\n') supposed to be fprintf(fid,'\n')?
Walter Roberson
le 2 Avr 2020
Some of your shape{i,2} or shape{i,3} are probably cell array of character vectors instead of being directly character vectors. Or possibly shape{i,1} or shape{i,4} is a cell containing a number.
Changyu Liu
le 2 Avr 2020
Walter Roberson
le 2 Avr 2020
Please show us
disp(shape(1,:))
Changyu Liu
le 2 Avr 2020
James Tursa
le 3 Avr 2020
So that is your answer, two of the cell elements are themselves cells, and you can't feed those directly to fprintf.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!