Cody

# Problem 43995. convert 2D array of ones and zeros to checkerboard array of [1,2] where the original array was ones and zero elsewhere

Solution 1180560

Submitted on 4 May 2017 by yurenchu
• Size: 10
• This is the leading solution.
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=ones(4); y_correct = [2,1,2,1 1,2,1,2 2,1,2,1 1,2,1,2]; assert(isequal(a_1_2_checkerboard_where_true(x),y_correct))

2   Pass
x = ones(3,2); y_correct = [2,1;1,2;2,1]; assert(isequal(a_1_2_checkerboard_where_true(x),y_correct))

3   Pass
y_correct = 2; assert(isequal(a_1_2_checkerboard_where_true(1),y_correct))

4   Pass
x = [... 0,1,0,1,0; 1,1,1,1,1; 0,1,0,1,0; 1,1,1,1,1; 0,1,0,1,0]; y_correct = [0,1,0,1,0; 1,2,1,2,1; 0,1,0,1,0; 1,2,1,2,1; 0,1,0,1,0]; assert(isequal(a_1_2_checkerboard_where_true(x),y_correct))

5   Pass
x = ones(5,5); x(2:3,2:3)=0; y_correct = [2,1,2,1,2; 1,0,0,2,1; 2,0,0,1,2; 1,2,1,2,1; 2,1,2,1,2]; assert(isequal(a_1_2_checkerboard_where_true(x),y_correct))

6   Pass
x=[1,1,0,0,0,0,0,0,0,1; 1,0,1,0,0,1,1,0,1,1; 1,0,1,0,1,1,1,1,1,1; 0,0,1,0,0,1,1,1,1,1; 0,1,0,0,0,0,0,0,1,1; 0,0,1,0,1,0,1,1,1,0; 1,1,1,0,0,0,0,1,0,0; 0,0,0,1,0,1,1,0,1,0; 1,0,1,1,0,0,0,0,1,0; 1,0,0,0,0,0,1,0,0,1]; y_correct = [2,1,0,0,0,0,0,0,0,1; 1,0,1,0,0,2,1,0,1,2; 2,0,2,0,2,1,2,1,2,1; 0,0,1,0,0,2,1,2,1,2; 0,1,0,0,0,0,0,0,2,1; 0,0,1,0,1,0,1,2,1,0; 2,1,2,0,0,0,0,1,0,0; 0,0,0,2,0,2,1,0,1,0; 2,0,2,1,0,0,0,0,2,0; 1,0,0,0,0,0,1,0,0,2]; assert(isequal(a_1_2_checkerboard_where_true(x),y_correct))

### Community Treasure Hunt

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

Start Hunting!