How count positive numbers, but when you get a negative, the sum stops. so then, sum the following sequence of positive numbers..
Show older comments
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
Accepted Answer
More Answers (2)
Wayne King
on 13 Oct 2012
Edited: Wayne King
on 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))
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!