Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

find seqence of values in an array

1 visualización (últimos 30 días)
Allan
Allan el 1 de Mzo. de 2016
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
I have an array of 1000-2000. Within that are some sequences of 4-5 elements. How can I find then?
  2 comentarios
Jan
Jan el 1 de Mzo. de 2016
Editada: Jan el 1 de Mzo. de 2016
Do you mean, that the array is a vector with 1000 to 2000 elements? And some neighboring 4 to 5 elements are equal? Or are you searching for a specific sequence of 4 to 5 elements?
Please edit the question and insert a small example with inputs and wanted outputs.
the cyclist
the cyclist el 1 de Mzo. de 2016
So, a small version would be that you have an array A like
A = [1 1 1 1 2 3 4 78 12 16 17 18 19 20 20 20 43]
and you want to find the sequences
1 2 3 4
and
16 17 18 19 20
?
What specifically do you want the output to be?

Respuestas (1)

Florian Bendl
Florian Bendl el 1 de Mzo. de 2016
Judging by your example: - Generate a difference vector B = diff(A); - Generate a logical from it B = B == 1; - Loop through the vector and note down when B switches from 0 to 1 and from 1 to 0 respectively. This will give you the beginning and the end of the sequences.- - Having the positions, you can easily choose the longest one.

La pregunta está cerrada.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by