Borrar filtros
Borrar filtros

Keeping count of consecutive of two vectors

1 visualización (últimos 30 días)
Daniel
Daniel el 17 de Feb. de 2016
Comentada: Jos (10584) el 17 de Feb. de 2016
I have two vectors.
A = [9 9 8 12 12 12 7 6 15 15 15 15 21 21 10 5 15 9 9 9 9 7 20 20 1 5 6 7 7];
B = [212 100 212 200 180 200 134 150 200 200 200 200 150 120 120 120 120 120 120 212 212 212 150 150 150 120 133 132 123 150];
I need to count how many times A == 9 && B >= 212 consecutively. As well as count 10 =< A < 15 && B >= 200 consecutively, and count where A>=15 && B>= 150 consecutively.
I'd appreciate any help.
  2 comentarios
Stephen23
Stephen23 el 17 de Feb. de 2016
The vectors A and B have different number of elements, therefore it is not possible to merge their logical relations like this: A == 9 & B >= 212.
Can you please show us the exact output that you expect for these input vectors.
Jos (10584)
Jos (10584) el 17 de Feb. de 2016
Well spotted, Stephen!

Iniciar sesión para comentar.

Respuestas (1)

Jos (10584)
Jos (10584) el 17 de Feb. de 2016
I am not really sure what you mean by consecutively. But this may help you further:
TF = A ==9 && B>= 212
will give you a sequence of true (1) and false (0). If you want to count how many times a true is followed by another true in TF.
MyCount = sum(TF(1:end-1) & TF(2:end))

Categorías

Más información sobre Creating and Concatenating Matrices 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