Shorten description of multiple fields and values in struct
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
does anyone have a method with a loop or other to shorten the description of multiple fields and values in struct?
=struct(Varnames{1},VarDec(:,:,1),Varnames{2},VarDec(:,:,2),Varnames{3},VarDec(:,:,3),Varnames{4},VarDec(:,:,4),Varnames{5},VarDec(:,:,5),Varnames{6},VarDec(:,:,6),Varnames{7},VarDec(:,:,7),Varnames{8},VarDec(:,:,8),Varnames{9},VarDec(:,:,9),Varnames{10},VarDec(:,:,10),Varnames{11},VarDec(:,:,11),Varnames{12},VarDec(:,:,12),Varnames{13},VarDec(:,:,13),Varnames{14},VarDec(:,:,14),Varnames{15},VarDec(:,:,15),Varnames{16},VarDec(:,:,16),Varnames{17},VarDec(:,:,17),Varnames{18},VarDec(:,:,18));
Thank you
Arnaud
0 件のコメント
採用された回答
Stephen23
2021 年 11 月 3 日
編集済み: Stephen23
2021 年 11 月 3 日
Either use CELL2STRUCT:
% Fake data:
Varnames = cellstr("X"+(1:18));
VarDec = randi(9,5,3,18);
% Convert to struct:
C = num2cell(VarDec,1:2);
S = cell2struct(C,Varnames,3)
Or a simple comma-separated list with STRUCT:
D = reshape(Varnames,1,[]);
D(2,:) = C;
S = struct(D{:})
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!