How to make diagonal matrices from a single column
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to make multiple diagonal matrices from a single colimn.
A=[1;2;3;4;5;6;7;8]
From this...
I want to make...
B=[1 0; 0 2]; [3 0; 0 4]; [5 0;0 6]; [7 0;0 8]
Then,
Each diagonal matrix is to be vertically attached.
So, from 10*1 to 10*2.
How can I do that?
Thanks,
0 Commenti
Risposta accettata
the cyclist
il 14 Ott 2019
B = zeros(8,2);
B(1:2:end,1) = A(1:2:end);
B(2:2:end,2) = A(2:2:end);
2 Commenti
the cyclist
il 15 Ott 2019
Modificato: the cyclist
il 15 Ott 2019
I think you got some of your math wrong there, but something like this should work:
A = 1:3744;
B = zeros(52,72);
for row = 1:numel(A)
col = mod(ia-1,72) + 1;
B(row,col) = A(row);
end
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Operating on Diagonal Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!