Borrar filtros
Borrar filtros

fprintf error:function not defined for struct inputs

2 visualizaciones (últimos 30 días)
Tomas
Tomas el 5 de Dic. de 2013
Comentada: Tomas el 5 de Dic. de 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

Respuestas (1)

Walter Roberson
Walter Roberson el 5 de Dic. de 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 comentario
Tomas
Tomas el 5 de Dic. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by