An alternative which uses repmat
is
A=[1 2; 3 4];
cell2mat(arrayfun(@(x)repmat(x,2,2),A,'UniformOutput',false))
ans =
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
arrayfun
is used to evaluate each element in A
using the anonymous function @(x)repmat(x,2,2)
which replicates that single element into a 2x2 matrix.
The result of arrayfun
is a 2x2 cell array where each element is a 2x2 matrix. We then convert this cell array into a matrix via cell2mat
.