How to find location of elements in an array

5 vues (au cours des 30 derniers jours)
Praanesh Sambath
Praanesh Sambath le 5 Juil 2020
I have 2 vectors 'A' of size 41*1 and 'B' of size 14*1
vector 'B' contains selected elements from vector 'A'. how do I find the position of elements present in vector 'b' in vector 'a'?
Example: A=1:1:100
B=2:2:20
Now I want to find the position of elements of B in A.
I tried find function but it throws dimention error.
Thanks in Advance

Réponses (2)

KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Juil 2020
Modifié(e) : KALYAN ACHARJYA le 5 Juil 2020
idx=find(ismember(A,B))
  5 commentaires
KALYAN ACHARJYA
KALYAN ACHARJYA le 5 Juil 2020
Yes, thank you Stephen Cobeldick sir
Praanesh Sambath
Praanesh Sambath le 5 Juil 2020
Thanks it worked

Connectez-vous pour commenter.


Kanupriya Singh
Kanupriya Singh le 5 Juil 2020
Try this-
a = [2 1 3 4 6 8]
b = [2 6 8]
idx = [];
for i = 1:length(b)
idx = [idx, find(b(i) == a)];
end
  2 commentaires
Stephen23
Stephen23 le 5 Juil 2020
Rather complex... one ismember call is much simpler (and is what most MATLAB users would do).
Praanesh Sambath
Praanesh Sambath le 5 Juil 2020
I get this error
error: horizontal dimensions mismatch (0x2 vs 1x1)
>> idx
idx = [](0x2)

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by