Cody

Problem 44439. Remove the air bubbles from a vector

Solution 2762842

Submitted on 31 Jul 2020 by tamir ben shitrit
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('bubbles.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

2   Pass
v = [1 3 0 5 0 -1]'; w_correct = [0 0 1 3 5 -1]'; assert(isequal(bubbles(v),w_correct))

NumberZero = 1×6 logical array 0 0 1 0 1 0 nzero = 0 0 number = 1×6 logical array 1 1 0 1 0 1 vnumber = 1 3 5 -1 w = 0 0 1 3 5 -1

3   Pass
v = [0 0 9 2 6]'; w_correct = v; assert(isequal(bubbles(v),w_correct))

NumberZero = 1×5 logical array 1 1 0 0 0 nzero = 0 0 number = 1×5 logical array 0 0 1 1 1 vnumber = 9 2 6 w = 0 0 9 2 6

4   Pass
v = [1 3 5 -1]'; w_correct = v; assert(isequal(bubbles(v),w_correct))

NumberZero = 1×4 logical array 0 0 0 0 nzero = 1×0 empty double row vector number = 1×4 logical array 1 1 1 1 vnumber = 1 3 5 -1 w = 1 3 5 -1

5   Pass
v = [0 1 0 1 1 1 0]'; w_correct = [0 0 0 1 1 1 1]'; assert(isequal(bubbles(v),w_correct))

NumberZero = 1×7 logical array 1 0 1 0 0 0 1 nzero = 0 0 0 number = 1×7 logical array 0 1 0 1 1 1 0 vnumber = 1 1 1 1 w = 0 0 0 1 1 1 1

Suggested Problems

More from this Author25

Community Treasure Hunt

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

Start Hunting!