Plot struct-data in loop

Hi, i have struct data: data_1, data_2.....data_100 iwant to make the following plot in a loop:
for k=1:100
plot(data_k.a,data_k.b)
end
how could i do this in matlab?

6 comentarios

Adam
Adam el 20 de Jul. de 2017
You mean you have 100 individually named structs or you have 1 struct with those 100 fields? If the latter than your plot instruction obviously needs to include the name of the struct itself. If the former why on earth would you do that rather than just create an array of 100 structs?!
Rica
Rica el 20 de Jul. de 2017
Editada: Rica el 20 de Jul. de 2017
I solve it in this manner as you mentioned:
for k=1:100
L=struct2cell(load(['data_' num2str(k) '.mat']))
aa(:,k)=L{1}.a;
bb(:,k)=L{1}.b;
end
thank you
Rica
Rica el 20 de Jul. de 2017
Thanks Stephen! Yes it is requirde and it does work for my case. I have diffrent struct with diffrent names. So i tried to collect the interessting data in an Array.
Stephen23
Stephen23 el 20 de Jul. de 2017
Editada: Stephen23 el 20 de Jul. de 2017
Aha... so someone put meta-data into structure names, and now this makes the saved data harder to process. Not very surprising. This is why meta-data does not belong in variable names:
Rica
Rica el 1 de Ag. de 2017
Thank You

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 20 de Jul. de 2017

Comentada:

el 1 de Ag. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by