building a diagonal matrix from another matrix!
3 次查看(过去 30 天)
显示 更早的评论
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)
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)
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!