Cody

# Problem 44887. Given a matrix A (size m x n) create a matrix B (size m+2 x n+2) which consists of matrix A surrounded by zeros. See Example below:

Solution 2884160

Submitted on 27 Aug 2020 by Jerry Wright
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 = ; y_correct = [0 0 0 0 1 0 0 0 0]; assert(isequal(zeroWrap(x),y_correct))

ans = 0 0 0 0 1 0 0 0 0

2   Pass
x = randi(10,4,5); m=zeroWrap(x); assert(isequal(m(2:end-1,2:end-1),x))

ans = 0 0 0 0 0 0 0 0 1 6 9 3 3 0 0 3 10 6 3 6 0 0 1 6 4 9 1 0 0 1 10 6 3 7 0 0 0 0 0 0 0 0

3   Pass
x = randi(10,4,5); m=zeroWrap(x); assert(isequal(sum(m(1,:)),0))

ans = 0 0 0 0 0 0 0 0 6 8 9 5 1 0 0 9 2 3 3 3 0 0 2 7 10 7 7 0 0 4 3 1 8 3 0 0 0 0 0 0 0 0

4   Pass
x = randi(10,4,5); m=zeroWrap(x); assert(isequal(sum(m(end,:)),0))

ans = 0 0 0 0 0 0 0 0 2 7 4 1 2 0 0 5 9 1 2 7 0 0 4 1 2 10 4 0 0 2 5 5 8 1 0 0 0 0 0 0 0 0

5   Pass
x = randi(10,4,5); m=zeroWrap(x); assert(isequal(sum(m(:,1)),0))

ans = 0 0 0 0 0 0 0 0 1 8 10 7 8 0 0 6 1 9 1 4 0 0 10 7 1 5 1 0 0 10 3 3 2 3 0 0 0 0 0 0 0 0

6   Pass
x = randi(10,4,5); m=zeroWrap(x); assert(isequal(sum(m(:,end)),0))

ans = 0 0 0 0 0 0 0 0 10 7 10 3 8 0 0 3 5 5 10 10 0 0 2 9 6 7 10 0 0 9 8 10 4 1 0 0 0 0 0 0 0 0

7   Pass
x = randi(10,4,5); m=zeroWrap(x); assert(isequal(size(m)-2,size(x)))

ans = 0 0 0 0 0 0 0 0 4 2 2 7 4 0 0 2 5 5 4 4 0 0 4 10 4 10 10 0 0 7 9 1 2 2 0 0 0 0 0 0 0 0

### Community Treasure Hunt

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

Start Hunting!