Populate structure array efficiently

조회 수: 2 (최근 30일)
Anon
Anon 2012년 8월 17일
Hi,
I am wondering if this question is too simple and if I am missing something important. How do I efficiently populate a structure array such that
A = 6:10;
and the resulting structure array is
S(1).A = 6;
S(2).A = 7;
...
S(5).A = 10;
Using a loop S is fairly easy to obtain, but there are probably much more efficient ways to do so.
Regards, Anon

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 8월 17일
S = struct('A',num2cell(A))
  댓글 수: 1
Anon
Anon 2012년 8월 17일
Aargh, I knew it should be easy. Thanks!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 8월 17일
It can be done, but it is not pretty.
S = struct( 'A', num2cell(6:10) )

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by