MATLAB: How to detect a sequence in an array [extended]

arrayfindMATLAB

Hello everybody,
let's say, I have this sequence: 1 – 770 – … (unknow amount of uninteresting numbers shortened with uaun) … – 897 – uaun – 769 – uaun – 897 – uaun – (continues in any way)
I would like to be able to detect how many times 770 is followed by 897 followed by 769. Additionally, I would like to calculate how many times 769 is followed by 897. 770-uaun-897-uaun-769-uaun-897 counts for both events.
Can someone think of an elegant way to program this? I can only think of an unbelievable complicated program with a lot of while-loops and break-commands.
Thank you in advance!
Marcus

Best Answer

v = [1 770 2 3 4 5 6 897 7 8 769 9 10 11 897 12 13 14 770 15 770 897 769] %demo data
filteredv = v(ismember(v, [770 769 897])); %get rid of uaun
seq1count = numel(strfind(filteredv, [770 897 769])) %despite its name strfind works with sequence of numbers
seq2count = numel(strfind(filteredv, [769 897]))