MATLAB: Changing blocks in a cell array

cell arrays

Hi,
I have a cell array which holds strings in certain columns and numerical values (doubles) in others. Can I change a whole block of numerical values in the cell array in one line of code (e.g. X(1:10,2) = ones(1,10), where X is a cell array) or do I need to do this using a "for" loop, repeating X{i,2} = 1 each time?
Thanks,
~K

Best Answer

You can do:
X(1:10,2) = num2cell(ones(1,10));
or:
X(1:10,2) = {1};
The class of the left hand side and right hand side of the assignment just need to be consistent in order for this to work in one line of code.