MATLAB: Comma separated list generation

blkdiagcomma-separated listMATLAB

How can you expand a comma separated list from a repetition? I am searching for the elegant way to do something like this:
Instead of
Y = blkdiag(X, X, X),
write Y = repblkdiag(X,3). The code I use now is:
function Y = repblkdiag(X, n)
Y = [];
for j = 1:n
Y = blkdiag(Y, X);
end
I expected that something like
Y = blkdiag(deal(repmat(X,3)))
would work. Thanks for your interest and contribution,
Jan

Best Answer

xc = repmat({X},1,3)
Y = blkdiag(xc{:})