Borrar filtros
Borrar filtros

Is there a function for argmax?

79 visualizaciones (últimos 30 días)
Javier Biera
Javier Biera el 5 de Jul. de 2018
Comentada: Walter Roberson el 7 de En. de 2020
I am looking for a function that selects the argmax value from a vector.
aux = argmax(P); %P is a normal vector
Supposedly there should a function directly called argmax, but is not working (error = Undefined function or variable 'argmax'). Is there any other function? (I am working with the 2017a version).
  5 comentarios
Anton Semechko
Anton Semechko el 5 de Jul. de 2018
Editada: Anton Semechko el 5 de Jul. de 2018
Use syntax
[P_max,id_max]=max(P);
Here, id_max is the index of P_max in P, so that P_max == P(id_max)
Stephen23
Stephen23 el 5 de Jul. de 2018
Editada: Stephen23 el 5 de Jul. de 2018
@Javier Biera: did you read the max documentation? It's second output is an index:
[~,idx] = max(...)

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 5 de Jul. de 2018
It's probably some function that someone wrote, like the person who gave you the code. Ask them for it. Otherwise, can you tell us how aux is used? That may give us some clue as to what argmax gives. Like it really should be nargin (the number of input arguments) or the max value of some matrix inputted into the argument list or who knows what.

Alan
Alan el 6 de En. de 2020
function y = argmax(x)
[~,y] = max(x);
end
  3 comentarios
Alan
Alan el 7 de En. de 2020
That is a step more comprehensive, but to cover all the edge cases would need a lot more work. In my opinion, there should be a standard MATLAB function for this.
Walter Roberson
Walter Roberson el 7 de En. de 2020
Easier I suspect to return
y == max(x, [], dim);
which would be a logical the same size as the original. That removes the need to worry about different sizes of output for different columns.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by