在Matlab中为行数组分配一行?

时间:2013-07-02 11:29:28

标签: matlab row variable-assignment cell-array

我正在尝试像使用矩阵一样:

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

1 个答案:

答案 0 :(得分:3)

更改

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

进入

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

(正常括号)。

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

line_params{1,:}

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

如果使用括号(()),则引用单元格条目,即将返回单元格数组。并且可以将单元格数组(单个项目)分配给另一个单元格数组(单个项目) - 前提是它们具有相同的尺寸。