フィルターのクリア

How to create a large size struct array?

11 ビュー (過去 30 日間)
Yuheng Huang
Yuheng Huang 2017 年 7 月 26 日
編集済み: Santa Raghavan 2017 年 7 月 26 日
I know I can create a struct array use struct function:
a = struct('data',{1,2,3});
But what if I want to create a 30d (or larger) struct array? Like:
a = a = struct('data',{1,2,3, ..., 30});

採用された回答

Santa Raghavan
Santa Raghavan 2017 年 7 月 26 日
編集済み: Santa Raghavan 2017 年 7 月 26 日
s = struct | struct(field,value) | struct(field1,value1,...,fieldN,valueN) | struct([]) | struct(obj)
My understanding is that you are trying to create a single field struct with large number of values inside it. Looking at the type of the "value" argument in the constructor, here is something that would work for your specific use case:
a = struct('data',num2cell(1:30))
Please refer to the value section under the Input Arguments header in Struct Doc
If you intend to create a field and populate it with large number of values in a loop, the easiest way would be to create a cell array obj and then use this as the value argument to construct the struct.
C = {};
for i = 1:30
C{i} = i;
end
a = struct('data',C);

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange结构体 についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!