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.
To find the max value of a column, use the MAX() aggregate function; it takes as its argument the name of the column for which you want to find the maximum value. If you have not specified any other columns in the SELECT clause, the maximum will be calculated for all records in the table.
You can use max() to get the max value. The max function can also return the index of the maximum value in the vector. To get this, assign the result of the call to max to a two element vector instead of just a single variable. Here, 7 is the largest number at the 4th position(index).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With