MATLAB Answers

Find/Match index of variable from an array

115 views (last 30 days)
hamzah khan
hamzah khan on 26 Feb 2020
Commented: hamzah khan on 26 Feb 2020
Hi, I have this code which I am using to find index of variable a from an array b
a = 2;
b =[ 1 2 3 4 5 6 7 8 9 10];
for i = 1:1:size(b,2)
if (find (a == b))
[~,zq(i)] = (min(b(i)- a));
The problem is the result "zq", in which I am getting all ones, so I donot know the position, where a is being matched.
Does any one know?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!