i have a matrix lets say
x =
2 2 3
4 3 2
6 4 8
now i want to get the location of a number 4. like i want ans like this
ans=(2,1) (3,2)
as these are the locations for 4 in matrix.
i have a matrix lets say
x =
2 2 3
4 3 2
6 4 8
now i want to get the location of a number 4. like i want ans like this
ans=(2,1) (3,2)
as these are the locations for 4 in matrix.
ismember will return an array of 1 or 0 depending on if the cell value there is or isn't the value you're searching for:
octave:9> x
x =
2 2 3
4 3 2
6 4 8
octave:10> ismember(x,4)
ans =
0
1
0
0
0
1
0
0
0
And then you can use find and ind2sub to get the array indicies of the 1s:
octave:11> [i,j] = ind2sub(size(x),find(ismember(x,4)))
i =
2
3
j =
1
2
So that the indicies are (2,1) and (3,2).