2012-07-12 13 views
5

ho creato un array di celle di struttura-file, in questo modo, per esempio:array di celle di struct-Files

>> 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. 

C'è una possibilità di abilitare l'accesso a tutti i nlgt_randlgt campi di res2-cellArray in una sola volta?

+1

dalla mia comprensione su come i dati sono organizzati in Matlab ... no – Rasman

risposta

5

Tutto ciò che devi fare è convertire il tuo res2 da un array di celle a un array struct (utilizzando cell2mat). Quindi puoi ottenere i membri della struttura esattamente come desideri. Ecco un esempio in cui cdat è un array di celle con due membri, s1 e 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 
2

è possibile accedere alla cella da:

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