MATLAB: How to populate a cell array without a for loop

cell arraysfor loopfunction

I find that I often create a cell array by writing code of this general format:
n = size(matrix, 1);
cell_array = cell(n, 1);
for i = 1:n
cell_array{i} = function(matrix(i, :), other_variables);
end
Is there a way to do this in one line, without a for loop?

Best Answer

cell_array = arrayfun( @(IDX) function(matrix(IDX,:), other_variables), (1:n).', 'uniform', 0);