How to find subscripts of matching element(s) in matlab/octave

Joel picture Joel · Nov 27, 2011 · Viewed 20k times · Source

Given a value in a matrix how can you get the subscript(s) at which the value occurs in the matrix?

So in this example

octave:27> X=rand(3)
X =

   0.46749   0.41187   0.26832
   0.91106   0.63567   0.97302
   0.71809   0.55269   0.84742

Given the value 0.26832 I would like to extract the subscript (1,3)

Answer

arne.b picture arne.b · Nov 27, 2011
[ix,iy]=find(X==0.26832)
ix = 
    1
iy = 
    3