構造体配列の要素の参照方法について
Show older comments
初歩的な質問で大変恐縮なのですが、
s.a = 1
s.b = [1,2]
s.c = 'test'
のような構造体配列sがある時、要素を指定する際にs.aと文字を使って指定するのではなく、s(1)がs.a, s(2)がs.bを指定しているのと同義になるような、数値を用いて指定することはできないでしょうか。
Accepted Answer
More Answers (1)
こんにちは.
関数 struct2cell を使うのがいちばん手っ取り早いかと思います.
s.a = 1;
s.b = [1,2];
s.c = 'test';
c = struct2cell(s);
c{1}
c{2}
c{3}
1 Comment
takeru misawa
on 13 Sep 2021
Categories
Find more on 構造体 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!