Forming a block diagonal matrix of one certain matrix?

조회 수: 4 (최근 30일)
diadalina
diadalina 2020년 1월 13일
편집: Matt J 2020년 1월 13일
I have a matrix A which is m*n. I want to create a block tridiagonal matrices of size n*m whose diagonals elements are the matrix A.
B=eye(3);
C=ones(2);
S=ones(2);
for i=1:numel(A)
A(i,i) =repmat(B,i,1)
A(i,i+1)=repmat(C,i,1)
A(i,i-1)=repmat(S,i,1)
end
can anyone help me to find the error
  댓글 수: 3
diadalina
diadalina 2020년 1월 13일
mY matrix A shoud be like this
A=B C 0000
S B C 000
0 S B C 00
00 S B C 0
where B, C,S are matrices
Adam Danz
Adam Danz 2020년 1월 13일
If that's the example of A, then A cannot be a matrix. Is it a cell array or is the example misleading?

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2020년 1월 13일
편집: Matt J 2020년 1월 13일
using interpMatrix (Download)
S=1*ones(2);
B=2*ones(2);
C=3*ones(2);
copies=4; %number of repetitions
L=flip( {S,B,C, zeros(size(B)) } );
idx=full(interpMatrix([1,2,3],2,copies,1))+1;
A=cell2mat(L(idx))
A =
2 2 3 3 0 0 0 0
2 2 3 3 0 0 0 0
1 1 2 2 3 3 0 0
1 1 2 2 3 3 0 0
0 0 1 1 2 2 3 3
0 0 1 1 2 2 3 3
0 0 0 0 1 1 2 2
0 0 0 0 1 1 2 2

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by