MATLAB: How to fill cell array with random numbers without for loop

cellcellfunrandom

I have created a cell array:
startSeedsX=cell(1,20);
Now I want each cell to have random number in the range 0 – 100:
startSeedsX=cellfun(@rand*100,startSeedsX);
Brings me error: Undefined operator '*' for input arguments of type 'function_handle'
I tried to put rand*100 in brackets (rand*100) or leave rand alone, doesn't help.
Is there a way to avoid for loop in that case?

Best Answer

Your definition of the function is incorrect. To fill a cell array with random numbers:
startSeedsX=arrayfun@(@() rand*100, 1:20, 'un', 0)
However, since each cell holds a single value, a regular array would be much more convenient:
startSeedsX = rand(1,20)*100