配列を構造体の形に変換
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
以下の配列から
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文を使う以外方法がわからず・・
実際には数万値の配列から構造体にしたく。
0 Kommentare
Antworten (1)
michio
am 7 Aug. 2020
に一覧がありますが、数値配列から直接構造体に変換する関数はありません。
個人的には table 型を経由するのがシンプルな気がしますので以下にサンプルを記載します。
mx = [1 11;2 22;3 33;];
mx_table = array2table(mx,'VariableNames',["a","b"]);
test = table2struct(mx_table);
test(1).a
参考になりましたら。
0 Kommentare
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!