Effacer les filtres
Effacer les filtres

Combining Matrices

5 vues (au cours des 30 derniers jours)
Syed Abbas
Syed Abbas le 6 Jan 2012
Hi, I have an upper traingular matrix andf a lower triangular matrix. Both have the exact same size. I want to combine these matrices along the diagonal to get a single composite matrix. How can I do that. Thanks.
  1 commentaire
Oleg Komarov
Oleg Komarov le 6 Jan 2012
Please supply an example.

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 6 Jan 2012
e.g.:
>> Ut = triu(randi(45,6))
Ut =
32 7 5 4 9 25
0 38 44 18 12 7
0 0 1 12 7 39
0 0 0 37 7 28
0 0 0 0 40 16
0 0 0 0 0 24
>> Lt = tril(randi(45,6))
Lt =
19 0 0 0 0 0
4 3 0 0 0 0
11 41 17 0 0 0
6 43 6 6 0 0
9 23 36 43 37 0
11 23 18 44 1 21
>> out1 = Ut + tril(Lt,-1)
out1 =
32 7 5 4 9 25
4 38 44 18 12 7
11 41 1 12 7 39
6 43 6 37 7 28
9 23 36 43 40 16
11 23 18 44 1 24
>> % OR
>> out2 = triu(Ut,1) + Lt
out2 =
19 7 5 4 9 25
4 3 44 18 12 7
11 41 17 12 7 39
6 43 6 6 7 28
9 23 36 43 37 16
11 23 18 44 1 21
>>
  1 commentaire
Syed Abbas
Syed Abbas le 6 Jan 2012
thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by