got confuse .. where is my mistake
1 次查看(过去 30 天)
显示 更早的评论
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/367156/image.jpeg)
0 个评论
回答(1 个)
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
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
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!