Given a matrix a, return a matrix b in which all the zeros have "bubbled" to the top. That is, any zeros in a given column should be moved to the top. The order of the remaining nonzero numbers in the column should be preserved.
Example 1
Input a = [ 1 2 3 0 4 5 6 0 0 ]
Output b is [ 0 0 0 1 2 3 6 4 5 ]
Example 2
Input a = [ 1 0 5 0 6 0 7 ]' Output b is [ 0 0 0 1 5 6 7 ]'
Example 3
Input a = [ 1 0 1 1 ] Output b is [ 1 0 1 1 ]
zeros are added to convert a logical to double.
The first time I see this kind of bsxfun.
Looks like I have the lamest possible solution!
I think it would be funny to see this solution in action by an animation of iterations! :-)
this breaks with nan's, solution 6118 does not
need to fix the test suite to include non-sorted non-zero elements
wishful thinking: perhaps sort 'should' behave like relational operators...
1900 Solvers
Back to basics 13 - Input variables
202 Solvers
What is the distance from point P(x,y) to the line Ax + By + C = 0?
207 Solvers
629 Solvers
Sum of odd numbers in a matrix
225 Solvers