Largest Value from the Row Sums of A

4 ビュー (過去 30 日間)
Sophie Culhane
Sophie Culhane 2020 年 9 月 27 日
コメント済み: Sophie Culhane 2020 年 9 月 27 日
I am to write a MATLAB function that takes as input a nonempty 2-dimensional array A and returns the largest value from the row sums of A. I currently have a program that works for everything except when the largest value is negative. I am asking for help to figure out how to open the program to all numbers. I am not allowed to use the max(A) command. Here is what I have so far:
function MaxRowSum = ex1(A)
%
%
[NRows,NCols] = size(A);
RowSum = zeros(NRows, 1);
MaxRowSum = zeros(1,1);
Largest = 0;
for row = 1:NRows
for col = 1:NCols
RowSum(row) = RowSum(row) + A(row,col);
end
if RowSum(row) > Largest
MaxRowSum = RowSum(row);
else
end
end

採用された回答

Bruno Luong
Bruno Luong 2020 年 9 月 27 日
Initialize with
Largest = -Inf % and not 0
  1 件のコメント
Sophie Culhane
Sophie Culhane 2020 年 9 月 27 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by