How do I write this code without a for loop?

조회 수: 2 (최근 30일)
Michelle
Michelle 2019년 3월 16일
댓글: Walter Roberson 2020년 11월 15일
Write a Matlab function that takes one input -- an MxN matrix -- and returns one output -- the row number of the matrix with the smallest row sum.
How do I rewirte this function without a for loop?
function min_row = min_row_sum(A)
min_row = 1;
min_total = 0;
[r, c] = size(A);
for i=1:r
total = 0;
for j=1:c
total = total+A(i, j);
end
if i==1 || total < min_total
min_row = i;
min_total = total;
end
end
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 11월 15일
Michelle, if you feel that the question is unclear, then as you are the person who posted the question, you should be the one who clarifies it to make it more clear.

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

답변 (1개)

madhan ravi
madhan ravi 2019년 3월 16일
Since it’s your homework sum along the rows and use min.
doc sum
doc min

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by