フィルターのクリア

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 Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by