find all minimum elements of 2 dimensional array in Matlab
Asked Answered
S

2

6

Having 2-dimensional array,A, I want to find minimum number in the array. However I can have more than one of that number. How can I find the [row col] of all minimum value? Example:

2 3 4 2
1 6 7 1
9 8 3 1

It should return [2,1] [2,4] [3,4]

Selfinduced answered 7/1, 2013 at 23:16 Comment(0)
H
4

find will do the trick:

[I,J] = find(A == min(A(:)) );

disp([I J])
   2   1
   2   4
   3   4
Humphrey answered 8/1, 2013 at 0:0 Comment(0)
H
2

I belive this should work

[row,col]=find(a==min(a(:)))

where a is your matrix. Find can also output a linear index if you give just one output.

Huambo answered 8/1, 2013 at 0:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.