Array of structural file cells

I created an array of structural file cells, for example, for example:

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

Is it possible to access all nlgt_randlgt-res2-cellarray fields at once?

+5
source share
2 answers

All you have to do is convert yours res2from an array of cells to an array of structures (using cell2mat). Then you can get the elements of the structure exactly as you want it. Here is an example where cdat- this is an array of structure cells with two members, s1and 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
+5
source

you can access the cell:

cellfun(@(r) r.nlgt_randlgt, res2);
+2
source

All Articles