Largest Value from the Row Sums of A

1 visualización (últimos 30 días)
Sophie Culhane
Sophie Culhane el 27 de Sept. de 2020
Comentada: Sophie Culhane el 27 de Sept. de 2020
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

Respuesta aceptada

Bruno Luong
Bruno Luong el 27 de Sept. de 2020
Initialize with
Largest = -Inf % and not 0

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by