Hi every one, I want to make a function that take two dimensional matrix as input and return sum of its diagonal (index for row and col will be same) and element right to this diagonal(sum of upper triangular elements). I am using that code & to me this is looking fine
function mysum=halfsum(A)[row col]=size(A);mysum=0;for i=1:row for j=1:col if i==j && i<=j mysum=mysum+A(i,j); end endendend
When i test for
>> a a = 1 2 3 4 >> halfsum(a) ans = 5
Best Answer