Populate structure array efficiently

1 回表示 (過去 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 Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by