I wanna create vector of structures
15 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Azzi Abdelmalek
2015-7-31
编辑:Azzi Abdelmalek
2015-7-31
ii=1:10
vec=struct('a',num2cell(ii),'b',num2cell(20-ii),'c',num2cell(ii+3))
0 个评论
Muthu Annamalai
2015-7-31
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!