Remove the air bubbles - MATLAB Cody - MATLAB Central

Problem 112. Remove the air bubbles

Difficulty:Rate

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

34.29% Correct | 65.71% Incorrect
Last Solution submitted on Mar 06, 2025

Problem Comments

Solution Comments

Show comments
Primes and Rough Numbers, Basic ideas
What is a rough number? What can they be used...
3
5

Problem Recent Solvers1211

Suggested Problems

More from this Author50

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page