Find/Match index of variable from an array

203 vues (au cours des 30 derniers jours)
Chris Dan
Chris Dan le 26 Fév 2020
Commenté : Chris Dan le 26 Fév 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));
end
end
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?
  2 commentaires
Alex Mcaulley
Alex Mcaulley le 26 Fév 2020
You are obtaining all ones because "b(i)- a" is scalar and the minimum value of a scalar is allways itself.
madhan ravi
madhan ravi le 26 Fév 2020
Second Alex.

Connectez-vous pour commenter.

Réponse acceptée

Bhaskar R
Bhaskar R le 26 Fév 2020
zq = find(b == a)
  2 commentaires
madhan ravi
madhan ravi le 26 Fév 2020
+1
Chris Dan
Chris Dan le 26 Fév 2020
Thanks (Y)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by