Assign array in field struct
Show older comments
class(Sis)
ans =
'struct'
length(Sis)
ans =
82
c=1
2
3
..
82
i want to create new field in struct
i want this:
Sis.b(1)=1;
Sis.b(2)=2;
..
Sis.b(82)=82;
now i want to semplify calculate
c=1:82
c=c'
>> [Sis.b]=c
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
3 Comments
Walter Roberson
on 9 Jul 2023
i want this:
Sis.b(1)=1;
Sis.b(2)=2;
Your Sis is a 1 x 82 struct. Sis.b(1) by structure expansion would be as if you had written
Sis(1).b, Sis(2).b, Sis(3).b, Sis(4).b, Sis(5).b ... Sis(82).b(1) = 1;
Sis(1).b, Sis(2).b, Sis(3).b, Sis(4).b, Sis(5).b ... Sis(82).b(2) = 2;
which is not what you want. You want the equivalent of
Sis(1).b = 1;
Sis(2).b = 2;
...
Sis(82).b = 82;
Vilém Frynta
on 9 Jul 2023
oh, i misunderstood. thanks
shamal
on 9 Jul 2023
Accepted Answer
More Answers (1)
Sis = struct();
Sis.b = 1:82'
Sis.b(1)
Sis.b(10)
Hope this helps.
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!