Comma separated list generation
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Andrei Bobrov
2011-6-22
xc = repmat({X},1,3)
Y = blkdiag(xc{:})
4 个评论
Teja Muppirala
2011-6-22
It is possible to do it in one line, but I think Andrei's solution is simpler.
Y = eval(['blkdiag( ' repmat('X,',1,3) '[])'])
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!