Hak*_*yar 5 matlab struct cell
我已经创建了一个结构文件的单元格数组,例如:
>> 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.
Run Code Online (Sandbox Code Playgroud)
是否有可能立即访问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
Run Code Online (Sandbox Code Playgroud)