How can I count the number of times a specific value appears within a range in a 1D vector?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Caesar Hernandez
le 27 Avr 2020
Commenté : per isakson
le 29 Avr 2020
Given a 1D vector, x, that has 600000 elements, how can I count the number of times the value 1 appears after the 150th position (excluding 150)?
0 commentaires
Réponse acceptée
Plus de réponses (2)
Ameer Hamza
le 27 Avr 2020
Modifié(e) : Ameer Hamza
le 27 Avr 2020
Try this.
x = randi([1 10], 1, 600000); % random vector
result = sum(x(151:end)==1);
per isakson
le 27 Avr 2020
If x is a vector of whole numbers
sum( double( x(151:end)==1 ) )
else
sum( double( abs(x(151:end)-1) < small_number ) )
2 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays 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!