got confuse .. where is my mistake

조회 수: 3 (최근 30일)
Abdur Rob
Abdur Rob 2020년 9월 27일
댓글: Abdur Rob 2020년 9월 27일
what should i do to solve OR where is my mistake
function summa = eja(A)
summa = 0;
[r c] = size(A);
for i = 1:r
summa = summa + (sum(A(r>=c)));
end
end

답변 (1개)

Alan Stevens
Alan Stevens 2020년 9월 27일
c is fixed as the last column. So in
[r c] = size(A);
for i = 1:r
summa = summa + (sum(A(r>=c)));
end
you are trying to sum the values of just those rows that are equal to or greater than the number of columns.
  댓글 수: 6
Alan Stevens
Alan Stevens 2020년 9월 27일
편집: Alan Stevens 2020년 9월 27일
@Abdur Rob Yes. That's what I said! I showed the lines that were giving the trouble. The following will do the sum you want:
function summa = eja(A)
summa = 0;
[r, c] = size(A);
for i = 1:r
summa = summa + sum(A(i,i:c));
end
end
Abdur Rob
Abdur Rob 2020년 9월 27일
thank you sir

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by