matlab - 结构文件元胞数组

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

是否有可能一次访问 res2-cellarray 的所有 nlgt_randlgt 字段?

最佳答案

您需要做的就是将您的 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

关于matlab - 结构文件元胞数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11443711/

相关文章:

ios - 将 UITableView Cell 滚动到表格边界之外

matlab - 在 MATLAB 中插入/填充真值网格中缺失的单元格

c - 初始化包含文件的结构

matlab - 将蒙太奇保存为图像 matlab

c - 在 C 中寻址嵌套结构的值

go - 在 Go 中获取子结构字段

iphone - 通过模态视图呈现详细 View Controller

matlab - 细胞中基于耐受性的独特载体

matlab - 使用矩阵索引创建矩阵

Matlab向量化-单元格的非零矩阵行索引