Borrar filtros
Borrar filtros

Finding repeating pairs of specific numbers within column

2 visualizaciones (últimos 30 días)
Phillip
Phillip el 18 de Mzo. de 2021
Comentada: Phillip el 19 de Mzo. de 2021
I'm stuck on this probably very trivial problem:
I have a matrix like this (just much larger!):
A = [1 2 4 10 11 12 14 17 19; 5 30 30 50 90 70 5 30 5]'
A =
1 5
2 30 <--
4 30
10 50
11 90
12 70
14 5
17 30 <--
19 5
I'm now looking for "pairs" of specific numbers in A(:, 2). For example, I'd like to find all 30s that are preceded by 5s in A(:, 2) and extract the corresponding row in A(:, 1).
So I'd like to end up, in this example, with B = [2, 17];
How can I do that?
  1 comentario
Phillip
Phillip el 19 de Mzo. de 2021
Vicky from stackoverflow solved this nicely - Thank you!!:
num_wanted=30;
num_previous=5;
is_match=[ false; A(1:end-1,2)==num_previous & A(2:end,2)==num_wanted ]; %the first element cannot be a match
A(is_match,1)

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Statistics and Machine Learning Toolbox 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!

Translated by