Find one array into another
Mostra commenti meno recenti
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!
Risposte (2)
numel(strfind(A,B))
2 Commenti
goodermes
il 18 Feb 2016
- for simple column vectors transpose them to become row vectors.
- for matrices, you could try this FEX submission:
Jos (10584)
il 18 Feb 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
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!