Cody

Problem 112. Remove the air bubbles

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 ]

Solution Stats

50.75% Correct | 49.25% Incorrect
Last solution submitted on Dec 02, 2016

Problem Comments

Solution Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more