Borrar filtros
Borrar filtros

How to find max number in an array without using the max function?

1 visualización (últimos 30 días)
Tara Milne
Tara Milne el 6 de Nov. de 2015
Comentada: Maaz Nayeem el 25 de Sept. de 2019
Ideally I want to try and use flow control to replace max in finding the maximum number in an array

Respuestas (1)

Image Analyst
Image Analyst el 6 de Nov. de 2015
Try this -- it's one of the first, basic things you learn in programming:
y = rand(20,40);
[rows, columns] = size(y);
yMax = -inf;
rowOfMax = 1;
colOfMax = 1;
for column = 1 : columns
for row = 1 : rows
if y(row, column) > yMax
yMax = y(row, column);
rowOfMax = row;
colOfMax = column;
end
end
end
fprintf('The max of y is %f.\nIt appears in row %d, column %d.\n', yMax, rowOfMax, colOfMax);
  1 comentario
Maaz Nayeem
Maaz Nayeem el 25 de Sept. de 2019
how do we find the maximum of two numbers in an array without using the max funcn and loops and constructs

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink 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