How to store structure data into an array in loop?

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일

0 개 추천

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?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2013년 5월 28일

편집:

2018년 6월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by