Convert a vector into a structure array field
27 ビュー (過去 30 日間)
古いコメントを表示
x= [2; 8; 6; 3; 7; 8];
for i=1:numel(x)
s(i).x=x(i);
end
Do the same, but without cycle.
0 件のコメント
採用された回答
Ray
2017 年 10 月 20 日
If struct s does not exist yet, you could use:
s = struct('x', num2cell(x));
3 件のコメント
Walter Roberson
2017 年 10 月 20 日
if x is the same length as the number of entries in the struct array s, then
temp = num2cell(x);
[s.x] = temp{:};
その他の回答 (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!