Really! fprintf cell error

조회 수: 1 (최근 30일)
Changyu Liu
Changyu Liu 2020년 4월 2일
댓글: Changyu Liu 2020년 4월 3일
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
Changyu Liu
Changyu Liu 2020년 4월 2일
>> disp(shape(1,:))
[1] {1×1 cell} {1×1 cell} [3.1416]
James Tursa
James Tursa 2020년 4월 3일
So that is your answer, two of the cell elements are themselves cells, and you can't feed those directly to fprintf.

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2020년 4월 3일
What happens if you change this
fprintf(fid, '%d %s %s %f',shape{i,:});
to this
fprintf(fid, '%d %s %s %f',shape{i,1},shape{i,2}{1},shape{i,3}{1},shape{i,4});
  댓글 수: 1
Changyu Liu
Changyu Liu 2020년 4월 3일
Much appreciated!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by