building a diagonal matrix from another matrix!
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hossein
am 7 Mär. 2014
Beantwortet: Jos (10584)
am 7 Mär. 2014
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 Kommentar
Jos (10584)
am 7 Mär. 2014
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?
Akzeptierte Antwort
Jos (10584)
am 7 Mär. 2014
A = 1:5 ;
B_sparse = spdiags(A(:),0,numel(A),numel(A))
B_full = diag(A)
isequal(full(B_sparse),B_full)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!