Effacer les filtres
Effacer les filtres

how to count number of transitions

6 vues (au cours des 30 derniers jours)
sakshi Garg
sakshi Garg le 16 Avr 2015
Commenté : Star Strider le 16 Avr 2015
i want to count the number of transitions in a 1-by-n binary array.
how to do it?
n does not exceed 10.

Réponses (1)

Star Strider
Star Strider le 16 Avr 2015
If you want to count both the positive [0 1] and negative [1 0] transitions, the easiest way is likely:
A = randi([0 1], 1, 25);
T = sum(diff(A)~=0);
If you want the positive and negative transitions separately:
PT = sum(diff(A)>0);
NT = sum(diff(A)<0);
  2 commentaires
sakshi Garg
sakshi Garg le 16 Avr 2015
thanks a lot
Star Strider
Star Strider le 16 Avr 2015
My pleasure.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by