Info

此问题已关闭。 请重新打开它进行编辑或回答。

WHY IT IS WRONG?

1 次查看(过去 30 天)
SAYANTAN BHANJA
SAYANTAN BHANJA 2017-7-15
关闭: James Tursa 2017-7-15
Write a function called halfsum that takes as input an at most two-dimensional array A and computes the sum of the elements of A that are in the lower right triangular part of A, that is, elements in the counter-diagonal (going from the bottom left corner, up and to the right) and elements that are to the right of it. For example, if the input is [1 2; 3 4; 5 6; 7 8], then the function would return 21.
function [H,r,c]=halfsum(x)
[r,c]=size(x);
if(c==2)
k=(r-2);
d=x';
z=flipud(d);
S=triu(z,k);
H=sum(S(:))
end
if(r==2)
k=(c-2);
z=flipud(x);
S=triu(z,k);
H=sum(S(:))
end
if(r>=c&&c~=2)
k=(r-3);
d=x';
z=flipud(d);
S=triu(z,k);
H=sum(S(:))
end
if(c>r&&r~=2)
k=(c-3);
z=flipud(x);
S=triu(z,k);
H=sum(S(:))
end
WHAT IS WRONG IN IT? GIVING WRONG RESULT FOR X=[1 2 3 4;4 5 6 8]

回答(0 个)

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by