Cody

# Problem 792. Set some matrix elements to zero

Solution 3274153

Submitted on 19 Oct 2020
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
x = [1 2 3 4 5 5 6 5 7 9 8 3]; y_correct = [0 0 0 4 0 0 6 0 0 9 0 0]; assert(isequal(your_fcn_name(x),y_correct))

b = 1 2 3 4 5 5 6 5 7 9 8 3

Matrix dimensions must agree. Error in your_fcn_name (line 4) if b ~= a Error in Test1 (line 7) assert(isequal(your_fcn_name(x),y_correct))

2   Fail
x = magic(4); y_correct = [16 0 0 0 0 11 0 0 0 0 0 12 0 0 15 0]; assert(isequal(your_fcn_name(x),y_correct))

b = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 y = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1

Assertion failed.

3   Pass
x = pi; y_correct = pi; assert(isequal(your_fcn_name(x),y_correct))

b = 3.1416 y = 3.1416

4   Pass
x = 0; y_correct = 0; assert(isequal(your_fcn_name(x),y_correct))

b = 0 y = 0

5   Fail
x = toeplitz(1:5); y_correct = [ 0 0 0 0 5 0 0 0 0 4 3 0 0 0 0 4 0 0 0 0 5 0 0 0 0]; assert(isequal(your_fcn_name(x),y_correct))

b = 1 2 3 4 5 2 1 2 3 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1 y = 1 2 3 4 5 2 1 2 3 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1

Assertion failed.

6   Fail
x = ones(5); y_correct = [ 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0]; assert(isequal(your_fcn_name(x),y_correct))

b = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 y = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Assertion failed.

7   Fail
x =nchoosek(7:9,3); y_correct =[ 0 0 9]; assert(isequal(your_fcn_name(x),y_correct))

b = 7 8 9 y = 7 8 9

Assertion failed.

8   Fail
x =nchoosek(4:9,2); y_correct = [ 0 5 0 6 0 7 0 8 0 9 0 6 0 7 0 8 0 9 0 7 0 8 0 9 0 8 0 9 0 9]; assert(isequal(your_fcn_name(x),y_correct))

b = 4 5 4 6 4 7 4 8 4 9 5 6 5 7 5 8 5 9 6 7 6 8 6 9 7 8 7 9 8 9

Matrix dimensions must agree. Error in your_fcn_name (line 4) if b ~= a Error in Test8 (line 17) assert(isequal(your_fcn_name(x),y_correct))

### Community Treasure Hunt

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

Start Hunting!