Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

WHY IT IS WRONG?

1 visualización (últimos 30 días)
SAYANTAN BHANJA
SAYANTAN BHANJA el 15 de Jul. de 2017
Cerrada: James Tursa el 15 de Jul. de 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]

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by