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

1 visualización (últimos 30 días)
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)

Respuesta aceptada

the cyclist
the cyclist el 9 de Abr. de 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);

Más respuestas (1)

darova
darova el 9 de Abr. de 2020
Here you go

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by