Given an array (row or column) of numbers, divide the array into consecutive positive/negative numbers.
0 is to be treated independently.
%input
x=[2 -2 1 4 5 0 -3 -2 1 -1 2 5 -7]
%output
y={[2], [-2], [1 4 5], [0], [-3 -2], [1], [-1], [2 5], [-7]}
%input
x=[1 -2 -3 4 5 6 -7 -8 -9 -10]'
%output
y={[1];[-2 -3]';[4 5 6]';[-7 -8 -9 -10]'}
However, loops and recursion are not allowed. Check the test suite for restrictions.
Solution Stats
Solution Comments
Show comments
Loading...
Problem Recent Solvers3
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15779 Solvers
-
3430 Solvers
-
Number of 1s in a binary string
10966 Solvers
-
Moving average (variable kernel length)
135 Solvers
-
Count number of words in string
186 Solvers
More from this Author44
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!