Effacer les filtres
Effacer les filtres

fprintf error:function not defined for struct inputs

2 vues (au cours des 30 derniers jours)
Tomas
Tomas le 5 Déc 2013
Commenté : Tomas le 5 Déc 2013
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

Réponses (1)

Walter Roberson
Walter Roberson le 5 Déc 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 commentaire
Tomas
Tomas le 5 Déc 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by