简体   繁体   中英

Matlab: compute the sum of elements in the lower portion of a matrix

在此处输入图片说明 在此处输入图片说明 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;

enter image description here 在此处输入图片说明

Can somebody provide me a solution on how to go about using looping to solve this problem ?

For an×m Matrix:

  1. Set the sum to 0, column to 1 and top to n (assuming (n,1) is the bottom-left corner of the matrix)

  2. Add to the sum all elements in current column which row number is more or equal to the top .

  3. Add 1 to column . If column is greater than m we are done.

  4. Subtract 1 from top . If top is 0 , set top to 1 .

  5. Go to 1.

对于矩阵M

Mysum = sum(sum(tril(rot90(M,-1))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM