Find one array into another
Afficher commentaires plus anciens
Hello everyone!
I've found similar discussions, but haven't found a solution for my case. I have an array A, for example [0 0 1 0 0 1 1 0 0 1 1 0 0 0] and want to know the number of times, when A consists array B=[ 1 1] - two consecutive ones. Not the number of ones in A in general, but a certain pattern. I can do this by making a cycle comparing element by element, but if the desired pattern is long it's not a good idea. Thank you in advance!
Réponses (2)
numel(strfind(A,B))
2 commentaires
goodermes
le 18 Fév 2016
- for simple column vectors transpose them to become row vectors.
- for matrices, you could try this FEX submission:
Jos (10584)
le 18 Fév 2016
for integer values you can (often) use the strfind trick
A = [1 1 0 1 0 1 1 1 0 1 0 1 0 1 1 0]
B = [1 1 0]
idx strfind(A,B)
% ans = 1 7 14
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!