Extracting values from struct array
Mostrar comentarios más antiguos
I have an struct array "one" = 98 x 1 cell. Each of these 98 rows has a field "C" with some values (2 x 2 x 56) complex double. How can I extract the value of "C" from all these 98 rows at once and save in a new variable?
Respuestas (1)
Walter Roberson
el 24 de En. de 2018
{one.C}
This would produce a 1 x 98 cell, each entry of which contained a 2 x 2 x 56 matrix.
3 comentarios
Syed Ayaz Mahmud
el 24 de En. de 2018
Walter Roberson
el 24 de En. de 2018
You said that "one" is a struct array, but you also say it is a cell ?? Is it a cell array in which each element is a scalar struct? If so then
cellfun(@(S) S.C, one, 'uniform', 0)
This gives out an error: "Struct contents reference from a non-struct array object."
Then what you have is not a struct array as your question states. You can read about struct arrays in the MATLAB documentation: https://www.mathworks.com/help/matlab/matlab_prog/access-multiple-elements-of-a-nonscalar-struct-array.html
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!