Reputation: 457
I have to develop a Matlab function that computes the sum of the elements in the reverse diagonal, and the elements to the right of the reverse diagonal. Sum (A) = 38 ; Sum (B) = 40; Sum (C) = 25;
Can somebody provide me a solution on how to go about using looping to solve this problem ?
Upvotes: 0
Views: 209
Reputation: 500
For a n×m Matrix:
Set the sum
to 0, column
to 1 and top
to n (assuming (n,1)
is the bottom-left corner of the matrix)
Add to the sum
all elements in current column which row number is more or equal to the top
.
Add 1 to column
. If column
is greater than m
we are done.
Subtract 1 from top
. If top
is 0
, set top
to 1
.
Go to 1.
Upvotes: 1