フィルターのクリア

How to create cell in the loop?

20 ビュー (過去 30 日間)
Donghui  Sun
Donghui Sun 2013 年 9 月 9 日
I create a struct each loop and want to use a cell to store these structs.I have no idea to implement the issue.
For example:
for I = 1:10
a = I;
b = I + 1;
tmpstruct = struct('a',a,'b',b);
% using cell to store the tmpstruct each loop
???
end
Assume the cell is CC.and I hope CC should be a 1*10 cell. Each element of CC is a struct. Any suggestion ?

採用された回答

Jan
Jan 2013 年 9 月 9 日
CC = cell(1, 10);
for I = 1:10
a = I;
b = I + 1;
tmpstruct = struct('a',a,'b',b);
CC{I} = tmpstruct;
end

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 9 月 9 日
Why are you using a cell array with structs inside it when a structure array would be so much simpler:
for k = 1:10
a = k;
b = k + 1;
tmpstruct(k) = struct('a',a,'b',b);
end
% Display it
tmpstruct

カテゴリ

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