Combining Matrices

3 次查看(过去 30 天)
Syed Abbas
Syed Abbas 2012-1-6
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.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-1-6
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
>>

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by