Convert a vector into a structure array field

 采纳的回答

If struct s does not exist yet, you could use:
s = struct('x', num2cell(x));

3 个评论

Thank you. And if it does exist and I want to add a field x?
if x is the same length as the number of entries in the struct array s, then
temp = num2cell(x);
[s.x] = temp{:};

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by