I wanna create vector of structures
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Why
"for i=1:10 vec(i)=struct('a',i, 'b',20-i, 'c',i+3); end"
does not work?
How can I correct it to create vectors of structures?
1 Commento
Risposte (2)
Azzi Abdelmalek
il 31 Lug 2015
Modificato: Azzi Abdelmalek
il 31 Lug 2015
ii=1:10
vec=struct('a',num2cell(ii),'b',num2cell(20-ii),'c',num2cell(ii+3))
0 Commenti
Muthu Annamalai
il 31 Lug 2015
You may also try, in addition to Azzi's code,
ii=1:10;
vec = arrayfun ( @(i) struct('a',i, 'b',20-i, 'c',i+3), ii );
depending on your stylistic preference.
0 Commenti
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!