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 1111277

Submitted on 27 Jan 2017 by Alexander Levedahl
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))

ans = 2 1 2 1 1 2 1 2 2 1 2 1 1 2 1 2 ans = 2 1 2 1 1 2 1 2 2 1 2 1 1 2 1 2

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))

ans = 2 1 1 2 2 1 ans = 2 1 1 2 2 1

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

ans = 2 ans = 2

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))

ans = 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 ans = 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

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))

ans = 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 ans = 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

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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