Convert a vector into a structure array field
31 次查看(过去 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 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!