配列を構造体の形に変換
이전 댓글 표시
以下の配列から
mx = [1 11;2 22;3 33;]
次のような構造体の形を作りたいです。
test(1).a = 1;test(2).a = 2;test(3).a = 3;
test(1).b = 11;test(2).b = 22;test(3).b = 33;
for文を使う以外方法がわからず・・
実際には数万値の配列から構造体にしたく。
답변 (1개)
michio
2020년 8월 7일
に一覧がありますが、数値配列から直接構造体に変換する関数はありません。
個人的には table 型を経由するのがシンプルな気がしますので以下にサンプルを記載します。
mx = [1 11;2 22;3 33;];
mx_table = array2table(mx,'VariableNames',["a","b"]);
test = table2struct(mx_table);
test(1).a
参考になりましたら。
카테고리
도움말 센터 및 File Exchange에서 ループと条件付きステートメント에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!