Octave: find the minimum value in a row, and also it's index

AG1 picture AG1 · Aug 10, 2017 · Viewed 13k times · Source

How would one find the minimum value in each row, and also the index of the minimum value?

octave:1> a = [1 2 3; 9 8 7; 5 4 6]
a =

   1   2   3
   9   8   7
   5   4   6

Answer

AG1 picture AG1 · Aug 10, 2017

This is hard to find in the documentation. https://www.gnu.org/software/octave/doc/v4.0.3/Utility-Functions.html

octave:2> [minval, idx] = min(a, [], 2)
minval =

   1
   7
   4

idx =

   1
   3
   2