필터 지우기
필터 지우기

building a diagonal matrix from another matrix!

조회 수: 4 (최근 30일)
Hossein
Hossein 2014년 3월 7일
답변: Jos (10584) 2014년 3월 7일
Hi eveybody,
im trying to build a diagonal matrix from another matrix in general form like following:
A=[a b,c d] -----> B[a 0 0 0,0 b 0 0,0 0 c 0,0 0 0 d]
dont want to write each array using blkdiag( ) function becuase my aimed matrix is too big.
tnx
  댓글 수: 1
Jos (10584)
Jos (10584) 2014년 3월 7일
What are a,b,c, and d? scalars or matrices?
What do you mean by "too big"? Did you consider using sparse storage using, for instance, SPDIAGS?

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

채택된 답변

Jos (10584)
Jos (10584) 2014년 3월 7일
A = 1:5 ;
B_sparse = spdiags(A(:),0,numel(A),numel(A))
B_full = diag(A)
isequal(full(B_sparse),B_full)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by