Filter löschen
Filter löschen

got confuse .. where is my mistake

1 Ansicht (letzte 30 Tage)
Abdur Rob
Abdur Rob am 27 Sep. 2020
Kommentiert: Abdur Rob am 27 Sep. 2020
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

Antworten (1)

Alan Stevens
Alan Stevens am 27 Sep. 2020
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 Kommentare
Alan Stevens
Alan Stevens am 27 Sep. 2020
Bearbeitet: Alan Stevens am 27 Sep. 2020
@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 am 27 Sep. 2020
thank you sir

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by