Matching Two Numeric Vectors
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have for instance a vector called A:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/223594/image.png)
And another vector called B:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/223595/image.png)
And another vector called C:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/223596/image.png)
I'd like another vector D which is:
- same length as vector B and C; and
- will show a 1 if:
- there is a match between vector A and vector B (else a 0); and
- the corresponding matched value in vector C is less than or equal to 30.
For instance:
B(1) = 149.1408, A(1) = 149.1408, C(1) = 5 <= 30 so D(1) = 1 etc etc.
Would also like a vector E (size of A) counting occurrences from vector D.
0 commentaires
Réponses (1)
Star Strider
le 8 Juin 2019
The ismembertol (link) function is likely appropriate. (Another option is the ismember (link) function, althoughit is likely not appropriate here.)
6 commentaires
Star Strider
le 8 Juin 2019
You actually don’t need any loops. You can do everything with the logical vectors.
You have to choose how to deal with the vectors not having the same numbers of elements. I can’t resolve that.
Voir également
Catégories
En savoir plus sur Logical 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!