# How to add Lower Triangular Matrix to Upper Matrix in matlab

How to add Lower Triangular Matrix to Upper Matrix in matlab

Please Check ... code .. I  m trying to add all the lower triangular part to upper triangular
part of matrix , so that zeros are substituted in lower triangular part ...
``````h = magic(6);
disp(h) ;
th =  triu(h);
disp(th);

indexthL = find (~triu(h));
indexthU = find (triu(h));

thU =  triu(h) ;
thL =  tril(h,-1) ;
``````
###### Who is Participating?

Commented:
I think you want to transpose (switching rows with columns, in other words) the result of tril and add it to some matrix.

Let's sey you want to add lower part of h to h:
h2 = h + triu(h');
or equally
h2 = h + tril(h)';

If you don't want to add the diagonal, use the 2nd parameter:
h2 = h + triu(h',1);
or equally
h2 = h + tril(h,-1)';
0

Commented:
I don't understand the question.

I've checked the code. There is some redundancy (like th and thU are the same thing, and instead of disp you could just remove ";" from the end of a statement), but all statements are correct. What are you trying to do again?
0

Commented:
If you add lower part (thL) to upper part (thU) you will get the original matrix h, so h == thL + thU will return true. I keep reading the question and still have no idea what you want to do.
0

Commented:
Sorry, I meant isequal(h,thU+thL).
0

FounderAuthor Commented:
Please check the File attached ,

I need to add the Values of Lower Triangular to upper Triangular , if you check  doc

The zeros mean .., that I need to add Values from Lower Part to Upper Triangular part at that place

Solution.odt
0

FounderAuthor Commented:
In case you need a  doc format of the file attached in my last comment  Solution.doc
0

FounderAuthor Commented:

Dear

The Matrix is Symmetric (18 X 18) , Need to add to upper matrix and the lower part , and substitute the
values of Lower matrix with zeros .. ,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.