Assign array in field struct
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Paul
2023 年 7 月 9 日
Example data
Sis(1).a = 1;
Sis(2).a = 2;
Sis(3).a = 3;
c = [30 40 50];
Assign elements of c to new field of elements of Sis
temp = num2cell(c);
[Sis.b] = temp{:};
Sis.b
Or in one line
clear
Sis(1).a = 1;
Sis(2).a = 2;
Sis(3).a = 3;
c = [30 40 50];
[Sis.b] = table2struct(table(c')).Var1;
Sis.b
3 件のコメント
Walter Roberson
2023 年 7 月 9 日
When you use table() and pass in an expression (instead of a variable name) then table() automatically uses 'Var' followed by the column number as the name of the variable. So for example table([10;20]; [30;40]) would produce a 2 x 2 table with variables 'Var1' and 'Var2'
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!