how i can return the index of an array?

1 view (last 30 days)
hey if the user select the number of an given array , how i can found the index of this number ? example: select one of thes number [22 23 44] and the user select the number 44 , how i can return the index of 44 which is 3 ?

Accepted Answer

John D'Errico
John D'Errico on 3 Dec 2016
Time to read the manual, given a basic problem. Either of these tools will do what you want:
help find
help ismember
  3 Comments
Image Analyst
Image Analyst on 3 Dec 2016
Edited: Image Analyst on 3 Dec 2016
Please thank John by "Accepting" his answer to give him credit/points for it.
If you have a floating point array instead of integers, use min() and abs()
[~, index] = min(abs(yourVector - 44))

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!