Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

WHY IT IS WRONG?

1 vue (au cours des 30 derniers jours)
SAYANTAN BHANJA
SAYANTAN BHANJA le 15 Juil 2017
Clôturé : James Tursa le 15 Juil 2017
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]

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by