Extracting values from struct array
Show older comments
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?
Answers (1)
Walter Roberson
on 24 Jan 2018
{one.C}
This would produce a 1 x 98 cell, each entry of which contained a 2 x 2 x 56 matrix.
3 Comments
Syed Ayaz Mahmud
on 24 Jan 2018
Walter Roberson
on 24 Jan 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
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!