Help counting a string of 1s in 2018a?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to write a function that will detect and count the number of strings of consecutive 1's in a vector.
For example, if I have a vector of [01110011100], I am looking for a function that will give me an answer of 2, as there are 2 strings of consequetive 1s
0 commentaires
Réponse acceptée
Raj
le 28 Mai 2019
You can use something like this:
A=[0 1 1 1 0 0 1 1 1 0 0]
A1 = [1,diff(A)]~=0;
Count = [A(A1)'];
Required_Answer=sum(Count(:) == 1)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Characters and Strings 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!