Cody

# Problem 611. surrounded matrix

Solution 3024400

Submitted on 1 Oct 2020 at 22:35
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; y_correct = ones(3); assert(isequal(surrounded(x),y_correct))

B = 1 1 1 1 1 1 1 1 1

2   Fail
x = [3 3 3;3 3 3]; y_correct = [1 1 1 1 1;1 3 3 3 1; 1 3 3 3 1; 1 1 1 1 1]; assert(isequal(surrounded(x),y_correct))

Unable to perform assignment because the size of the left side is 3-by-4 and the size of the right side is 2-by-3. Error in surrounded (line 4) B(2:r+2,2:c+2)=A; Error in Test2 (line 3) assert(isequal(surrounded(x),y_correct))

3   Fail
x = ones(3,4); y_correct = ones(5,6); assert(isequal(surrounded(x),y_correct))

Unable to perform assignment because the size of the left side is 4-by-5 and the size of the right side is 3-by-4. Error in surrounded (line 4) B(2:r+2,2:c+2)=A; Error in Test3 (line 3) assert(isequal(surrounded(x),y_correct))

4   Fail
x = [0]; y_correct = ones(3); y_correct(2,2) = 0; assert(isequal(surrounded(x),y_correct))

B = 1 1 1 1 0 0 1 0 0

Assertion failed.

5   Fail
x = reshape(1:9,[3,3]); y_correct = [1 1 1 1 1; 1 1 2 3 1; ... 1 4 5 6 1; 1 7 8 9 1; 1 1 1 1 1]'; assert(isequal(surrounded(x),y_correct))

Unable to perform assignment because the size of the left side is 4-by-4 and the size of the right side is 3-by-3. Error in surrounded (line 4) B(2:r+2,2:c+2)=A; Error in Test5 (line 4) assert(isequal(surrounded(x),y_correct))

### Community Treasure Hunt

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

Start Hunting!