2012-07-12 150 views
5

我創建的結構文件的單元陣列,像這樣的例子:單元陣列

>> 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場?

+1

從我的理解上的數據如何在Matlab中的組織......沒有 – Rasman 2012-07-12 01:12:02

回答

5

您只需將res2從單元格陣列轉換爲結構數組(使用cell2mat)即可。然後你可以完全按照你想要的方式獲得結構成員。以下是一個示例,其中cdat是包含兩個成員的結構的單元陣列,s1s2

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 
2

您可以通過訪問該單元:

cellfun(@(r) r.nlgt_randlgt, res2);