필터 지우기
필터 지우기

fprintf error:function not defined for struct inputs

조회 수: 2 (최근 30일)
Tomas
Tomas 2013년 12월 5일
댓글: Tomas 2013년 12월 5일
I have an input argument that is a 1x1 struct
this is my code
function escrevecircuitos(circuito, fid)
if fid == 1 fprintf(fid,'%8s %13s %2s %2s %9s %7s\r\n', 'circuito', 'nome_ficheiro', 'SE', 'ID', 'Perimetro', 'Recorde'); for i = 1:length(circuito) fprintf('%20s %14.1s %2.6f %1.6f %2.6f %1.6f %4d %1:2:3f\r\n',circuito(i).circuito,circuito(i).nome_ficheiro,circuito(i).SE(1),circuito(i).ID,circuito(i).Perimetro,circuito(i).Recorde); end end
How can i solve the problem,the error is
Error using fprintf Function is not defined for 'struct' inputs.
Error in escrevecircuitos (line 7) fprintf('%20s %14.1s %2.6f %1.6f %2.6f %1.6f %4d %1:2:3f\r\n',circuito(i).circuito,circuito(i).nome_ficheiro,circuito(i).SE(1),circuito(i).ID,circuito(i).Perimetro,circuito(i).Recorde)
Thank you for the help

답변 (1개)

Walter Roberson
Walter Roberson 2013년 12월 5일
That looks okay at the moment, unless one of the fields inside circuito is itself a structure. Perhaps circuito(i).circuito or circuito(i).Perimetro
Try this to help debug
fn = fieldnames(circuito);
for K = 1 : length(circuito)
for f = 1 : length(fn)
if isstruct( circuito(K).(fn{f}) )
fprintf('Index %d field %s is structure\n', K, fn{f} );
end
end
end
  댓글 수: 1
Tomas
Tomas 2013년 12월 5일
both circuito(1).SE and circuito(i).ID are 1x1 structures,
how can solve this?i need the fprintf to give me the two values inside SE and ID

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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by