Populate structure array efficiently

1 Ansicht (letzte 30 Tage)
Anon
Anon am 17 Aug. 2012
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

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 17 Aug. 2012
S = struct('A',num2cell(A))
  1 Kommentar
Anon
Anon am 17 Aug. 2012
Aargh, I knew it should be easy. Thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

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

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by