MATLAB Answers

## finding the position of a number?

Asked by Sivakumaran Chandrasekaran

### Sivakumaran Chandrasekaran (view profile)

on 27 Mar 2013
Accepted Answer by Youssef Khmou

### Youssef Khmou (view profile)

a=[1 2 3;4 5 6] b=2 i should compare b with all elements of a and to find the corresponding position in a ... e.g., the answer should be (1,2). what command or what method should i use

## 1 Answer

### Youssef Khmou (view profile)

Answer by Youssef Khmou

### Youssef Khmou (view profile)

on 27 Mar 2013
Edited by Youssef Khmou

### Youssef Khmou (view profile)

on 27 Mar 2013
Accepted answer

try this way

` a=[1 2 3;4 5 6]; b=2;`
``` [x,y]=find(a==b);
A=[x,y]; ```

Image Analyst

### Image Analyst (view profile)

on 27 Mar 2013

I wouldn't call it x,y - I'd call it row, column. Because usually x is the column (horizontal location), not the row as you have it.

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

New to MATLAB?