MATLAB: Assign value zero to n elements of cell array

cell arraysMATLAB

Hi all,
I am declaring a cell array to hold some numeric and non numeric data. I want to set the first row, all columns, equal to the numeric value zero. Something like this:
myCell = cell(5, 500);
myCell{1,:} = 0;
Which gives the error:
The right hand side of this assignment has too few values to satisfy the left hand side.
I've tried a number of other things, none worked, so have resorted to doing it in a loop. It works, but I really don't like it. Is there a simple way I'm missing?
Cheers, Karl

Best Answer

myCell(1,:) = {0}
  • Left hand side: use () to keep it as cells not braces for extraction of the content of cells.
  • Right handside: make 0 a 1x1 cell so that it can be stuck into all of the cells on the left via scalar expansion