How count positive numbers, but when you get a negative, the sum stops. so then, sum the following sequence of positive numbers..
이전 댓글 표시
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
채택된 답변
추가 답변 (2개)
Wayne King
2012년 10월 13일
편집: Wayne King
2012년 10월 13일
x = randn(100,1);
sum(x(x>0))
For an example with integers:
x = randi([-5 5],20,1);
sum(x(x>0))
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!