How do I write this code without a for loop?
1 回表示 (過去 30 日間)
古いコメントを表示
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
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
2019 年 3 月 16 日
Since it’s your homework sum along the rows and use min.
doc sum
doc min
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!