【问题标题】:Multidimensional 3D Cell Arrays多维 3D 单元阵列
【发布时间】:2017-02-25 23:24:07
【问题描述】:

如何创建这个多维 3D 元胞数组? https://www.mathworks.com/help/matlab/math/ch_data_struct6.gif

【问题讨论】:

  • 由于元胞数组可以容纳任何其他Matlab类型(包括元胞数组),您可以将数据填入其中。
  • 嗯,我实际上需要创建一个 3D 单元格数组,其中每个单元格有 5 个变量(不同类型),我可以稍后使用 for 循环为其赋值。我对这种结构的语法有疑问。
  • @Rotem ........
  • 好的,附图说明了输出格式,但是输入的格式是什么?请发布您的代码(到目前为止您有什么?)。

标签: arrays matlab cell


【解决方案1】:

您链接的图像不是 3D 单元阵列,而是 3D 结构阵列。例如,包含第一个“患者”信息的结构可以通过以下方式构建:

patient(1,1,2).name = 'Al Smith';
patient(1,1,2).billing = 504.70;
patient(1,1,2).test = [80 80 80; 153 153 154; 181 190 183];

【讨论】:

    【解决方案2】:

    我可以帮助你处理第一个病人:

    %Allocate 3D empty cell array (cell array dimension is 2x2x2).
    patient = cell(2, 2, 2);
    
    %Set details of first patient.
    patient{1, 1, 2}.name = 'Al Smith'; %Set name field (string).
    patient{1, 1, 2}.billing = 504.70;  %Set billing field (double).
    patient{1, 1, 2}.test = [80, 80, 80; 153, 153, 154; 181, 190, 182]; %Set test field (3x3 matrix).
    
    %Continue with next patient:
    patient{1, 2, 2}.name = 'Dora Jones';
    %...
    %...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-10
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 2013-06-07
      • 2017-02-24
      相关资源
      最近更新 更多