Suzan Cioc
Suzan Cioc

Reputation: 30137

Assign a row to cell array in Matlab?

I am trying to do this as with matrices:

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

but getting error above.

Types are following:

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

Upvotes: 2

Views: 5727

Answers (1)

Rody Oldenhuis
Rody Oldenhuis

Reputation: 38042

Change

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

into

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

(normal parenthesis).

If you use curly braces ({}), you reference the individual elements. That is,

line_params{1,:}

will return a comma-separated list of elements in the cell line_params in its first row. You cannot assign a cell array (single item) to a comma-separated list (multiple items).

If you use parenthesis (()), you reference the cell entry, i.e., a cell array will be returned. And you can assign a cell array (single item) to another cell array (single item) -- provided they have the same dimensions of course.

Upvotes: 4

Related Questions