Variable number of input matrices in a function
이전 댓글 표시
I want to change the code below so the function blkdiag can take on any number of matrices A, based on the value of N.
N = 3;
A_1 = sparse(1:N,1:N,-1*ones(N,1),N,N+1);
A_2 = sparse(1:N,2:N+1,1*ones(N,1),N,N+1);
A = A_1+A_2;
out = full(blkdiag(A,A,A))
So suppose N=4, then
out = full(blkdiag(A,A,A,A))
And so on.
How can I create a variable input for this function, based on a value?
Thanks,
Tim
댓글 수: 3
madhan ravi
2019년 2월 4일
편집: madhan ravi
2019년 2월 4일
A = {A_1+A_2};
A=repelem(A,N);
out = full(blkdiag(horzcat(A{:}))) % or
out = full(blkdiag(vertcat(A{:})))
Tim de Reijer
2019년 2월 4일
편집: Tim de Reijer
2019년 2월 4일
madhan ravi
2019년 2월 4일
편집: madhan ravi
2019년 2월 4일
True , apologies didn't verify the results.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!