How can I Create a vector from a structure composed by tables?
Mostrar comentarios más antiguos
Hi guys,
i'm new to matlab, ad i'd like to create a column vector from a structure. Every structure component is a 22x9 Table, and the vector i want to build should take a specific cell from every Tables. For exaple, i want row 22, column "RicoveratiConSintomi" of every tables.
x=struct("apr1",apr1,"apr2",apr2,"apr3",apr3,"apr4",apr4,"apr5",apr5,"apr6",apr6,"apr7",apr7);
x.apr1(22,"RicoveratiConSintomi");
n=length(fieldnames(x));
vecname=NaN(n,1);
and from here i don't really know how to write the For cycle to get what i want.
Thanks to everyone will try to help me!
Respuestas (1)
darova
el 12 de Abr. de 2020
Maybe something like this
x=struct("apr1",apr1,"apr2",apr2,"apr3",apr3,"apr4",apr4,"apr5",apr5,"apr6",apr6,"apr7",apr7);
% x.apr1(22,"RicoveratiConSintomi");
n=length(fieldnames(x));
s = fieldnames(x);
vecname=NaN(n,1);
for i = 1:n
str = getfield(x,s(i));
vecname(i) = str(22,"RicoveratiConSintomi");
end
Or better be to create an array structure
x=struct("apr",{apr1 apr2 apr3 apr4 apr5 apr6 apr7});
x.apr1(22,"RicoveratiConSintomi");
n = length(x);
vecname=NaN(n,1);
for i = 1:n
vecname(i) = x(i).apr(22,"RicoveratiConSintomi");
end
1 comentario
Stephen23
el 12 de Abr. de 2020
Good advice to use a non-scalar structure:
Categorías
Más información sobre Structures en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!