Cody

Problem 1193. Insert zeros into vector

Solution 1972385

Submitted on 12 Oct 2019 by nguyen thai son son
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
x = [1 2 3 4 5]; n = 2; y_correct = [1 0 0 2 0 0 3 0 0 4 0 0 5 0 0]; assert(isequal(insert_zeros(x,n),y_correct))

y = [] y = 1 y = 1 0 0 y = 1 0 0 2 y = 1 0 0 2 0 0 y = 1 0 0 2 0 0 3 y = 1 0 0 2 0 0 3 0 0 y = 1 0 0 2 0 0 3 0 0 4 y = 1 0 0 2 0 0 3 0 0 4 0 0 y = 1 0 0 2 0 0 3 0 0 4 0 0 5 y = 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0

2   Pass
x = [1 2 3 4 5]; n = 1; y_correct = [1 0 2 0 3 0 4 0 5 0]; assert(isequal(insert_zeros(x,n),y_correct))

y = [] y = 1 y = 1 0 y = 1 0 2 y = 1 0 2 0 y = 1 0 2 0 3 y = 1 0 2 0 3 0 y = 1 0 2 0 3 0 4 y = 1 0 2 0 3 0 4 0 y = 1 0 2 0 3 0 4 0 5 y = 1 0 2 0 3 0 4 0 5 0

3   Pass
x = [1 2]; n = 5; y_correct = [1 0 0 0 0 0 2 0 0 0 0 0]; assert(isequal(insert_zeros(x,n),y_correct))

y = [] y = 1 y = 1 0 0 0 0 0 y = 1 0 0 0 0 0 2 y = 1 0 0 0 0 0 2 0 0 0 0 0

4   Pass
x = 1:10; n = 1; y_correct = [1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0]; assert(isequal(insert_zeros(x,n),y_correct))

y = [] y = 1 y = 1 0 y = 1 0 2 y = 1 0 2 0 y = 1 0 2 0 3 y = 1 0 2 0 3 0 y = 1 0 2 0 3 0 4 y = 1 0 2 0 3 0 4 0 y = 1 0 2 0 3 0 4 0 5 y = 1 0 2 0 3 0 4 0 5 0 y = 1 0 2 0 3 0 4 0 5 0 6 y = 1 0 2 0 3 0 4 0 5 0 6 0 y = 1 0 2 0 3 0 4 0 5 0 6 0 7 y = 1 0 2 0 3 0 4 0 5 0 6 0 7 0 y = 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 y = 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 y = 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 y = 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 y = 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 y = 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0

5   Pass
x = 1:4; n = 10; y_correct = [1 0 0 0 0 0 0 0 0 0 0 ... 2 0 0 0 0 0 0 0 0 0 0 ... 3 0 0 0 0 0 0 0 0 0 0 ... 4 0 0 0 0 0 0 0 0 0 0]; assert(isequal(insert_zeros(x,n),y_correct))

y = [] y = 1 y = 1 0 0 0 0 0 0 0 0 0 0 y = 1 0 0 0 0 0 0 0 0 0 0 2 y = 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 y = 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 3 y = Columns 1 through 30 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 Columns 31 through 33 0 0 0 y = Columns 1 through 30 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 Columns 31 through 34 0 0 0 4 y = Columns 1 through 30 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 Columns 31 through 44 0 0 0 4 0 0 0 0 0 0 0 0 0 0

6   Pass
x = -3:3; n = 3; y_correct = [-3 0 0 0 -2 0 0 0 -1 0 0 0 0 0 0 0 ... 1 0 0 0 2 0 0 0 3 0 0 0]; assert(isequal(insert_zeros(x,n),y_correct))

y = [] y = -3 y = -3 0 0 0 y = -3 0 0 0 -2 y = -3 0 0 0 -2 0 0 0 y = -3 0 0 0 -2 0 0 0 -1 y = -3 0 0 0 -2 0 0 0 -1 0 0 0 y = -3 0 0 0 -2 0 0 0 -1 0 0 0 0 y = -3 0 0 0 -2 0 0 0 -1 0 0 0 0 0 0 0 y = -3 0 0 0 -2 0 0 0 -1 0 0 0 0 0 0 0 1 y = -3 0 0 0 -2 0 0 0 -1 0 0 0 0 0 0 0 1 0 0 0 y = -3 0 0 0 -2 0 0 0 -1 0 0 0 0 0 0 0 1 0 0 0 2 y = -3 0 0 0 -2 0 0 0 -1 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 y = -3 0 0 0 -2 0 0 0 -1 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 3 y = -3 0 0 0 -2 0 0 0 -1 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 3 0 0 0

7   Pass
x = [11 17 42 81 39]; n = 2; y_correct = [11 0 0 17 0 0 42 0 0 81 0 0 39 0 0]; assert(isequal(insert_zeros(x,n),y_correct))

y = [] y = 11 y = 11 0 0 y = 11 0 0 17 y = 11 0 0 17 0 0 y = 11 0 0 17 0 0 42 y = 11 0 0 17 0 0 42 0 0 y = 11 0 0 17 0 0 42 0 0 81 y = 11 0 0 17 0 0 42 0 0 81 0 0 y = 11 0 0 17 0 0 42 0 0 81 0 0 39 y = 11 0 0 17 0 0 42 0 0 81 0 0 39 0 0

8   Pass
x = 2:3:20; n = 1; y_correct = [2 0 5 0 8 0 11 0 14 0 17 0 20 0]; assert(isequal(insert_zeros(x,n),y_correct))

y = [] y = 2 y = 2 0 y = 2 0 5 y = 2 0 5 0 y = 2 0 5 0 8 y = 2 0 5 0 8 0 y = 2 0 5 0 8 0 11 y = 2 0 5 0 8 0 11 0 y = 2 0 5 0 8 0 11 0 14 y = 2 0 5 0 8 0 11 0 14 0 y = 2 0 5 0 8 0 11 0 14 0 17 y = 2 0 5 0 8 0 11 0 14 0 17 0 y = 2 0 5 0 8 0 11 0 14 0 17 0 20 y = 2 0 5 0 8 0 11 0 14 0 17 0 20 0

Suggested Problems

More from this Author9

Community Treasure Hunt

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

Start Hunting!