Assign array in field struct
显示 更早的评论
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 个评论
Walter Roberson
2023-7-9
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
2023-7-9
oh, i misunderstood. thanks
shamal
2023-7-9
采纳的回答
更多回答(1 个)
Sis = struct();
Sis.b = 1:82'
Sis.b(1)
Sis.b(10)
Hope this helps.
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!