Nested structure

9 views (last 30 days)
Ganesh
Ganesh on 18 May 2011
I am interested in reading data from a field of a structure which is within many layers of structures. data = info.ROIcontour1.Slice1.contourdata; This fetches the contourdata from slice#1 of the first ROI. I would like to read all the slices of that ROI and store inside 'data'. Obviously, doing this manually for 100s of slices is not fun. I am not aware of a solution using a simple For loop. Suggest me ways.
Thanks, Ganesh

Accepted Answer

Walter Roberson
Walter Roberson on 18 May 2011
fn = fieldnames(info.ROIcontour1);
fn = fn(strncmp(fn,'Slice',5));
nf = length(fn);
contourslices = cell(nf,1);
for K = 1 : nf
countourslices{K} = info.ROIcontour1.(fn{K}).contourdata;
end

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!