【问题标题】:Assign a row to cell array in Matlab?在 Matlab 中为单元格数组分配一行?
【发布时间】:2013-07-02 11:29:27
【问题描述】:

我正在尝试使用矩阵来做到这一点:

>> line_params{1,:} = {numberPatterns{i}, lw, iw};
The right hand side of this assignment has too few values to satisfy the left hand side.

但上面出现错误。

类型如下:

>> class(line_params)
ans =
cell

>> size(line_params)
ans =
    21     3

>> a={numberPatterns{i}, lw, iw};

>> class(a)
ans =
cell

>> size(a)
ans =
     1     3

【问题讨论】:

    标签: matlab row variable-assignment cell-array


    【解决方案1】:

    改变

    line_params{1,:} = {numberPatterns{i}, lw, iw}
    

    进入

    line_params(1,:) = {numberPatterns{i}, lw, iw}
    

    (正常括号)。

    如果您使用花括号 ({}),您将引用各个元素。也就是说,

    line_params{1,:}
    

    将在第一行的单元格line_params 中返回一个逗号分隔的元素列表。您不能将元胞数组(单个项目)分配给以逗号分隔的列表(多个项目)。

    如果使用括号 (()),则引用单元格条目,即,将返回一个单元格数组。您可以将一个元胞数组(单个项目)分配给另一个元胞数组(单个项目)——当然前提是它们具有相同的维度。

    【讨论】:

      猜你喜欢
      • 2013-07-25
      • 2016-08-30
      • 1970-01-01
      • 2012-06-07
      • 2016-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多