got confuse .. where is my mistake

1 回表示 (過去 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 Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by