convert from myStruct(i​ndex).Log{​index2}.ID to myStruct(i​ndex).Log.​ID(index2)

1 view (last 30 days)
Hi people,
I'm having some trouble with cell arrays and structures.
I have the following cell array within a structure:
myStruct(index).Log{index2}.ID
Log is a cell array and it has different lengths for different "index"
I need to remove the cell array and get only structs, like this:
myStruct(index).Log.ID(index2)
In this way, I can do the following:
my_IDs = myStruct(1:2).Log.ID
Is there a way to convert it? Thank you

Answers (1)

Walter Roberson
Walter Roberson on 8 Nov 2011
Something like this might work:
newstruct = arrayfun( @(Sidx) struct('Log', struct('ID', cellfun(@(S) S.ID, myStruct(Sidx).Log) )), 1:length(myStruct) );
I think I unpeeled all the parts correctly, but I do not promise.

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!