Clear Filters
Clear Filters

fprintf error:function not defined for struct inputs

2 views (last 30 days)
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

Answers (1)

Walter Roberson
Walter Roberson on 5 Dec 2013
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 Comment
Tomas
Tomas on 5 Dec 2013
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

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!