Counting the number of occurences of a specific (defined) sequence within a vector
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ondrej Benes
el 9 de Abr. de 2020
Comentada: Ondrej Benes
el 9 de Abr. de 2020
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 comentarios
Respuesta aceptada
the cyclist
el 9 de Abr. de 2020
d = diff(vector)>0;
[isInc,runLenTmp,startIndexTmp] = RunLength(d);
keepRun = isInc & runLenTmp>=3;
runLen = runLenTmp(keepRun) + 1;
startIndex = startIndexTmp(keepRun);
Más respuestas (1)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!