How to create a semi-diagonal matrix
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Konstantinos Tsitsilonis
il 21 Nov 2017
Commentato: Konstantinos Tsitsilonis
il 22 Nov 2017
Hi all,
I have been trying to create a semi-diagonal matrix; Now I know this may not be the right terminology for it, however here it is (also, the matrix doesnt have to be square. I want to have control over its m x n dimensions. The example is thus of a semi-diagonal 3 x 6 matrix):
M_3x6 = [1 1 0 0 0 0
0 0 1 1 0 0
0 0 0 0 1 1] ;
Or for a larger matrix:
M_4x7 = [1 1 0 0 0 0 0
0 0 1 1 0 0 0
0 0 0 0 1 1 0
0 0 0 0 0 0 1] ;
Thanks for your help in advance,
KMT.
0 Commenti
Risposta accettata
Stephen23
il 21 Nov 2017
Modificato: Stephen23
il 21 Nov 2017
>> blkdiag([1,1],[1,1],[1,1])
ans =
1 1 0 0 0 0
0 0 1 1 0 0
0 0 0 0 1 1
>>
>> C = repmat({[1,1]},1,4);
>> blkdiag(C{:})
ans =
1 1 0 0 0 0 0 0
0 0 1 1 0 0 0 0
0 0 0 0 1 1 0 0
0 0 0 0 0 0 1 1
>>
Then use indexing to select a part of the matrix.
Method two: repelem: With newer MATLAB versions you could use eye and repelem, and then use indexing as above.
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!