I have a structure within a structure (a nested structure), and am trying to add a field to that structure, what should I write?
4 views (last 30 days)
Show older comments
s.Field.(FieldName)=zeros(1,1);
Doesn't work...
0 Comments
Answers (1)
Fabian Schadt
on 23 Mar 2017
Edited: Stephen23
on 23 Mar 2017
Hi Guy Nir,
actually there should be no problem.
s.Field.FieldName = zeros(1,1);
works ;-)
However, if you state your nested struct with brackets ->
s.Field.(FieldName),
then you access with (FieldName) a variable in your workspace. If this does not exist, you receive an error.
If brackets, then it would be like this:
FieldName = [];
s.Field.(FieldName) = zeros(1,1);
Hope I could help!
See Also
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!