Get structure elements across fields
Mostrar comentarios más antiguos
I have a 1-by-n structure with -m- fields. All the elements of the structure are single numbers.
I want to get all the elements across any particular 'row' of the structure as a vector.
For example, I need to access [struct(n).field1 struct(n).field2 ... struct(n).fieldm] without having to go through the individual fields.
Respuesta aceptada
Más respuestas (1)
Azzi Abdelmalek
el 28 de Dic. de 2014
Editada: Azzi Abdelmalek
el 28 de Dic. de 2014
Another way:
d=struct('f1',num2cell(randi(10,1,10)),'f2',num2cell(randi(10,1,10)),'f3',num2cell(randi(10,1,10)))
n=4
e=d(n)
nf=fieldnames(d)
for k=1:numel(nf)
v(k,1)=e.(nf{k})
end
1 comentario
Oyeniyi
el 28 de Dic. de 2014
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!