How count positive numbers, but when you get a negative, the sum stops. so then, sum the following sequence of positive numbers..
Afficher commentaires plus anciens
Example
v =
1 1 -1 1 1 1 -1 -1 1
%sum the sequence of positive numbers that are together
sol =
2 3 1
Regards Claudio
Réponse acceptée
Plus de réponses (2)
Wayne King
le 13 Oct 2012
Modifié(e) : Wayne King
le 13 Oct 2012
x = randn(100,1);
sum(x(x>0))
For an example with integers:
x = randi([-5 5],20,1);
sum(x(x>0))
1 commentaire
Javier
le 13 Oct 2012
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!