I am looking for a decent way to create and initialize a cell array with a given value. I can think of the following oneliner
val = 'hello';
dim = [2, 4, 6];
arrayfun(@(x) val, zeros(dim), 'UniformOutput', false)
but I feel dirty.
I am looking for a decent way to create and initialize a cell array with a given value. I can think of the following oneliner
val = 'hello';
dim = [2, 4, 6];
arrayfun(@(x) val, zeros(dim), 'UniformOutput', false)
but I feel dirty.
If you want to avoid arrayfun
, you could do
C = cell(dim);
C(:) = {val};
or
C = cell(dim);
[C{:}] = deal(val);