indexing a field in a structure
Show older comments
I need to save every mean from this structure into a vector. (there are 270 fields)
m_vector(1:270) = s(11).structure.mean(1:270) does not work and I am not sure why
2 Comments
matthias daeumer
on 9 Oct 2020
"I need to save every mean from this structure into a vector. (there are 270 fields)"
I very much doubt that there are 270 fields. Most likely you are confusing the number of fields (displayed as headers in the Variable Viewer) with the number of elements in the structure (displayed as rows). In fact these are totally independent things.
But until you actually upload the data in a mat file by clicking on the paperclip button, we will have to rely on guessing.
Accepted Answer
More Answers (1)
Ameer Hamza
on 9 Oct 2020
Edited: Ameer Hamza
on 9 Oct 2020
Try this
all_means = cell2mat(arrayfun(@(i) {[s(i).structure.mean]}, 1:numel(s)))
% or
all_means = cell2mat(arrayfun(@(s_) {[s_.structure.mean]}, s))
Categories
Find more on Characters and Strings 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!