Borrar filtros
Borrar filtros

Find the first position of maximum value in a Matrix

43 visualizaciones (últimos 30 días)
Moe
Moe el 5 de Mayo de 2014
Comentada: suchismita el 18 de Jun. de 2014
Hello everyone,
Suppose there can be the max value at more than one location, how can I catch the first max value.
A = [6;7;21;4;9;21;5;1];
max(A(:))
[maxValue, linearIndexesOfMaxes] = max(A(:));
[rowsOfMaxes colsOfMaxes] = find(A == maxValue)
ans =
21
rowsOfMaxes =
3
6
colsOfMaxes =
1
1
Then I want it to be:
ans =
21
rowsOfMaxes =
3
colsOfMaxes =
1
Can anyone please help me?
  1 comentario
the cyclist
the cyclist el 5 de Mayo de 2014
I'm confused as to why you are referring to rows and columns, when the original input is a vector, not a matrix.

Iniciar sesión para comentar.

Respuesta aceptada

José-Luis
José-Luis el 5 de Mayo de 2014
Editada: José-Luis el 5 de Mayo de 2014
[maxValue, linearIndexesOfMaxes] = max(A(:));
[rowsOfMaxes colsOfMaxes] = find(A == maxValue,1,'first')
Please accept an answer if it helped you.
  2 comentarios
Moe
Moe el 5 de Mayo de 2014
Thanks Jose. It was very helpful.
suchismita
suchismita el 18 de Jun. de 2014
if i want to find the 3rd max value as '9' and its position...what shall i do?????

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matched Filter and Ambiguity Function en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by