Counting the number of occurences of a specific (defined) sequence within a vector

1 view (last 30 days)
I have a randon vector and I need to identify and count how many times a given sequence - at least 3 consecutive numbers, each larger than the other - occurs in the vector.
Then create a table with all indexes marking the start of the sequence and the lenght of the sequence
vector=randn(1,100);
Then I was thinking using some kind of for loop but ... I suck.
for i=lenght(vector)
if vector(i)<vector(i+1)<vector(i+2)

Accepted Answer

the cyclist
the cyclist on 9 Apr 2020
I would download the excellent RunLength utility from the File Exchange, and then ...
d = diff(vector)>0;
[isInc,runLenTmp,startIndexTmp] = RunLength(d);
keepRun = isInc & runLenTmp>=3;
runLen = runLenTmp(keepRun) + 1;
startIndex = startIndexTmp(keepRun);

More Answers (1)

darova
darova on 9 Apr 2020
Here you go

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!