Cody

# Problem 868. Replace all zeros and NaNs in a matrix with the string 'error'

Solution 2014562

Submitted on 11 Nov 2019
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   Fail
A = 1; assert(isequal({1},replace_zeros_and_NaNs(A)))

C = 1×1 cell array {[1]}

Undefined function 'eq' for input arguments of type 'cell'. Error in replace_zeros_and_NaNs (line 3) C(find(C == {NaN})) = 'error' Error in Test1 (line 2) assert(isequal({1},replace_zeros_and_NaNs(A)))

2   Fail
A = [1 0; NaN 1]; C_correct = {1, 'error'; 'error', 1}; assert(isequal(C_correct, replace_zeros_and_NaNs(A)))

C = 1×1 cell array {2×2 double}

Undefined function 'eq' for input arguments of type 'cell'. Error in replace_zeros_and_NaNs (line 3) C(find(C == {NaN})) = 'error' Error in Test2 (line 3) assert(isequal(C_correct, replace_zeros_and_NaNs(A)))

3   Fail
A = []; assert(isequal({}, replace_zeros_and_NaNs(A)))

C = 1×1 cell array {0×0 double}

Undefined function 'eq' for input arguments of type 'cell'. Error in replace_zeros_and_NaNs (line 3) C(find(C == {NaN})) = 'error' Error in Test3 (line 2) assert(isequal({}, replace_zeros_and_NaNs(A)))

4   Fail
A = magic(5); A([14 3 5 6 7]) = 0; A([1 18 15 20 22]) = NaN; C_correct = {'error' 'error' 1 8 15; 23 'error' 7 14 'error';'error' 6 13 'error' 22; 10 12 'error' 21 3; 'error' 18 'error' 'error' 9}; assert(isequal(C_correct, replace_zeros_and_NaNs(A)))

C = 1×1 cell array {5×5 double}

Undefined function 'eq' for input arguments of type 'cell'. Error in replace_zeros_and_NaNs (line 3) C(find(C == {NaN})) = 'error' Error in Test4 (line 3) assert(isequal(C_correct, replace_zeros_and_NaNs(A)))