how i can return the index of an array?
1 view (last 30 days)
Show older comments
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 ?
0 Comments
Accepted Answer
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
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))
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!