Search code examples
positionmaxoctaveargmax

Octave position of maximum value in column


I want to find the argmax of the values in a matrix by column, e.g.:

1 2 3    2 3 3
4 5 6 -> 
3 7 8 

I feel like I should just be able to map an argmax/posmax function over the columns, but I don't see a particularly intuitive way to do this in Octave.


Solution

  • Read max function documentation here

    [max_values indices] = max(input);
    

    Example:

    input =
    
    1   2   3
    4   5   6
    3   7   8
    
    [max_values indices] = max(input)
    max_values =
    
    4   7   8
    
    indices =
    
    2   3   3