单元阵列
问题描述:
我创建的结构文件的单元阵列,像这样的例子:单元阵列
>> res2
res2 =
Columns 1 through 7
[1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct]
Columns 8 through 10
[1x1 struct] [1x1 struct] [1x1 struct]
>> res2{1}
ans =
nchi005_randchi005: 0.1061
nfdr_randfdr: 0.0011
nlgt_randlgt: 2.9517e-004
nphast_randphast: 0.6660
ndd_rand_dd: 0.0020
ndd_rand_dd_larger: 1
>> res2{1}.nlgt_randlgt
ans =
2.9517e-004
>> res{:}.nlgt_randlgt
??? Bad cell reference operation.
是否有一个方法可行访问RES2-cellarray的一次全nlgt_randlgt场?
答
您只需将res2
从单元格阵列转换为结构数组(使用cell2mat
)即可。然后你可以完全按照你想要的方式获得结构成员。以下是一个示例,其中cdat
是包含两个成员的结构的单元阵列,s1
和s2
。
cdat =
[1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct] [1x1 struct]
>> dat = cell2mat(cdat)
dat =
1x10 struct array with fields:
s1
s2
>> [dat(:).s1]
ans =
1 1 1 1 1 1 1 1 1 1
答
您可以通过访问该单元:
cellfun(@(r) r.nlgt_randlgt, res2);
从我的理解上的数据如何在Matlab中的组织......没有 – Rasman 2012-07-12 01:12:02