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에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!