Counting the number of occurences of a specific (defined) sequence within a vector
1 view (last 30 days)
Show older comments
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)
0 Comments
Accepted Answer
the cyclist
on 9 Apr 2020
d = diff(vector)>0;
[isInc,runLenTmp,startIndexTmp] = RunLength(d);
keepRun = isInc & runLenTmp>=3;
runLen = runLenTmp(keepRun) + 1;
startIndex = startIndexTmp(keepRun);
More Answers (1)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!