MATLAB Answers


How to determine the position of an integer

Asked by Vivekram
on 9 May 2013


I have a very basic question. I have a variable containing 5 numbers, say for eg,

d= [1 4 3 2 5]

how can i find the position of the number 3 in this d. I tried to use Find but I think I am using it wrong . Can anyone help me out please.





No products are associated with this question.

3 Answers

Answer by John Doe
on 9 May 2013
Edited by John Doe
on 9 May 2013
 Accepted answer

If you want to use the find function:

pos = find(d==3);

  1 Comment

Hi Robert,

Ya , I tried it out but unfortunately the values are in cell format. Thereby giving me an error saying:

Undefined function or method 'eq' for input arguments of type 'cell'.

Can you suggest a way?


Answer by Jim O'Doherty on 9 May 2013

Hi Vivekram,

I'd sugget using the "unique" command

[C, ia, ic]=unique(d)

ic will give you the indices of the numbers in your array d


  1 Comment

Hi Jim,

How will it give me the position of the digit 4 only? and the other thing that I forgot to mention is that the values are in a cell format.


Answer by Grzegorz Knor
on 9 May 2013
Edited by Grzegorz Knor
on 9 May 2013

If the values are in the cell format use cell2mat function:

pos = find(cell2mat(d)==3)


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!