Am 13.12.2013 16:00, schrieb Qi Shi:
Dear all,
how to transform a square matrix to a diagonal matrix using commands?
for example, we have A={2,1;1,3}, how can I get a matrix B={2,0;0,3}?
For example:
diag(A)**ones(1,cols(A)) .* I(cols(A))
I'm not guaranteeing that this is the most elegant way, but in general
you should probably think about whether extracting diag(A) isn't enough
for your purposes, because it contains the same information.
-sven