How to store structure data into an array in loop?

4 次查看(过去 30 天)
I have a structure with many fields of different length.I want to store this structure data into an array in a loop.How to solve this issue.

回答(1 个)

Matt J
Matt J 2013-5-28
As in the following example
>> s.a=1; s.b=[2 3]; %A struct
a: 1
b: [2 3]
>> C=struct2cell(s); [C{:}]
ans =
1 2 3
  2 个评论
Loretta Laughrey
Loretta Laughrey 2018-6-21
编辑:Loretta Laughrey 2018-6-21
What if I want an array of structures so that:
s(1) = struct(1,[2,3])
s(2) = struct(4,[5,6])
Stephen23
Stephen23 2018-6-21
编辑:Stephen23 2018-6-21
@Loretta Laughrey: Neither struct(1,[2,3]) nor struct(4,[5,6]) are valid calls to struct, because the first input must be the fieldname. What output do you expect to get?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by