Extract pattern and subsequent n elements from array and count number of occurences

Viewed 194

I have an array of doubles like this:

C = [1 2 3 4 0 3 2 5 6 7 1 2 3 4 150 30]

i want to find the pattern [1 2 3 4] within the array and then store the 2 values after that pattern with it like:

A = [1 2 3 4 0 3]
B = [1 2 3 4 150 30]

i can find the pattern like this but i don't know how to get and store 2 values after that with the previous one.

And after finding A, B if i want to find the number of occurrences of each arrays within array C how can i do that?

indices = cellfun(@(c) strfind(c,pattern), C, 'UniformOutput', false);

Thanks!

2 Answers
Related