matlab - Indexing over all values in nested struct -
i have nested struct contains values , defined as:
mystruct.level1.a = 1; mystruct.level1.b = 2; mystruct.level2.a = 8; mystruct.level2.b = 9;
i want perform operations on elements in level1 , level2. want access values in level1 , level2, put them in vector, without referencing nested field names.
e.g. i'd like:
level1_vector = [mystruct.level1]
which output:
level1_vector = [1 2]
how can that?
use combination of 2 functions below:
cell2mat(struct2cell(mystruct.level1))
Comments
Post a Comment