creating a structure in for loop
10 ビュー (過去 30 日間)
古いコメントを表示
Hello,
Is it possible to create a structure in a for loop
field={'name1','name2'}
for i=1:2
structure.(field{i})=value
end
Output:
structure.name1=value
structure.name2=value
Thanks
Jinang
2 件のコメント
Ruger28
2019 年 11 月 22 日
Please, use the code format.
What are you having issues with? This will work just fine.
採用された回答
Stephen23
2019 年 11 月 22 日
Use the syntax shown in the MATLAB documentation:
>> a = {'see','why'};
>> KPI = {'L','L2','L3'};
>> S.(a{1}).(KPI{1}) = 5;
>> S.see.L
ans = 5
Read more:
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!