Search code examples
matlabcellcells

How to set a number in a couple of cells within a cell array


Possible Duplicate:
Assign a value to multiple cells in matlab

I am trying to enter a number, lets say 3, into all the cells in column 2 that are empty.

Like this:

emptyList = cellfun(@isempty,anscell)
anscell{emptyList(:,2),2}=3

but I get this message that

The right hand side of this assignment has too few values to satisfy the left hand side.

Can I overcome it without loops and creating sum and ones functions?


Solution

  • Is this what you need?

    anscell = cell(3,2)
    emptyList = cellfun(@isempty,anscell)
    anscell(emptyList(:,2),2)={3}