Cody

# Problem 792. Set some matrix elements to zero

Solution 1898980

Submitted on 13 Aug 2019 by Yuumi Ozaki
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 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))

rot = 4 5 3 3 6 8 2 5 9 1 5 7 maxs = 4 6 9 r = 3 c = 4 x = 0 2 3 4 5 5 6 5 7 9 8 3 x = 0 0 3 4 5 5 6 5 7 9 8 3 x = 0 0 0 4 5 5 6 5 7 9 8 3 x = 0 0 0 4 0 5 6 5 7 9 8 3 x = 0 0 0 4 0 0 6 5 7 9 8 3 x = 0 0 0 4 0 0 6 0 7 9 8 3 x = 0 0 0 4 0 0 6 0 0 9 8 3 x = 0 0 0 4 0 0 6 0 0 9 0 3 x = 0 0 0 4 0 0 6 0 0 9 0 0 p = 4 t = 4 p = 4 t = 3 p = 4 t = 2 y = 0 0 0 4 0 0 6 0 0 9 0 0

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

rot = 13 8 12 1 3 10 6 15 2 11 7 14 16 5 9 4 maxs = 16 11 12 15 r = 4 c = 4 x = 16 0 3 13 5 11 10 8 9 7 6 12 4 14 15 1 x = 16 0 0 13 5 11 10 8 9 7 6 12 4 14 15 1 x = 16 0 0 0 5 11 10 8 9 7 6 12 4 14 15 1 x = 16 0 0 0 0 11 10 8 9 7 6 12 4 14 15 1 x = 16 0 0 0 0 11 0 8 9 7 6 12 4 14 15 1 x = 16 0 0 0 0 11 0 0 9 7 6 12 4 14 15 1 x = 16 0 0 0 0 11 0 0 0 7 6 12 4 14 15 1 x = 16 0 0 0 0 11 0 0 0 0 6 12 4 14 15 1 x = 16 0 0 0 0 11 0 0 0 0 0 12 4 14 15 1 x = 16 0 0 0 0 11 0 0 0 0 0 12 0 14 15 1 x = 16 0 0 0 0 11 0 0 0 0 0 12 0 0 15 1 x = 16 0 0 0 0 11 0 0 0 0 0 12 0 0 15 0 p = 4 t = 1 p = 4 t = 2 p = 4 t = 4 p = 4 t = 3 y = 16 0 0 0 0 11 0 0 0 0 0 12 0 0 15 0

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

rot = 3.1416 maxs = 3.1416 r = 1 c = 1 p = 1 t = 1 y = 3.1416

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

rot = 0 maxs = 0 r = 1 c = 1 p = 1 t = [] y = 0

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

rot = 5 4 3 2 1 4 3 2 1 2 3 2 1 2 3 2 1 2 3 4 1 2 3 4 5 maxs = 5 4 3 4 5 r = 5 c = 5 x = 0 2 3 4 5 2 1 2 3 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1 x = 0 0 3 4 5 2 1 2 3 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1 x = 0 0 0 4 5 2 1 2 3 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1 x = 0 0 0 0 5 2 1 2 3 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1 x = 0 0 0 0 5 0 1 2 3 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1 x = 0 0 0 0 5 0 0 2 3 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1 x = 0 0 0 0 5 0 0 0 3 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1 x = 0 0 0 0 5 0 0 0 0 4 3 2 1 2 3 4 3 2 1 2 5 4 3 2 1 x = 0 0 0 0 5 0 0 0 0 4 3 0 1 2 3 4 3 2 1 2 5 4 3 2 1 x = 0 0 0 0 5 0 0 0 0 4 3 0 0 2 3 4 3 2 1 2 5 4 3 2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0 0 1 0 0 0 0 p = 1 y = 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

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

rot = 9 8 7 maxs = 9 r = 1 c = 3 x = 0 8 9 x = 0 0 9 p = 3 t = 3 y = 0 0 9

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

rot = 5 6 7 8 9 6 7 8 9 7 8 9 8 9 9 4 4 4 4 4 5 5 5 5 6 6 6 7 7 8 maxs = 5 6 7 8 9 6 7 8 9 7 8 9 8 9 9 r = 15 c = 2 x = 0 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 x = 0 5 0 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 x = 0 5 0 6 0 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 x = 0 5 0 6 0 7 0 8 4 9 5 6 5 7 5 8 5 9 6 7 6 8 6 9 7 8 7 9 8 9 x = 0 5 0 6 0 7 0 8 0 9 5 6 5 7 5 8 5 9 6 7 6 8 6 9 7 8 7 9 8 9 x = 0 5 0 6 0 7 0 8 0 9 0 6 5 7 5 8 5 9 6 7 6 8 6 9 7 8 7 9 8 9 x = 0 5 0 6 0 7 0 8 0 9 0 6 0 7 5 8 5 9 6 7 6 8 6 9 7 8 7 9 8 9 x = 0 5 0 6 0 7 0 8 0 9 0 6 0 7 0 8 5 9 6 7 6 8 6 9 7 8 7 9 8 9 x = 0 5 0 6 0 7 0 8 0 9 0 6 0 7 0 8 0 9 6 7 6 8 6 9 7 8 7 9 8 9 x = 0 5 0 6 0 7 0 8 0 9 0 6 0 7 0 8 0 9 0 7 6 8 6 9 7 8 7 9 8 9 x = 0 5 0 6 0 7 0 8 0 9 0 6 0 7 0 8 0 9 0 7 0 8 6 9 7 8 7 9 8 9 x = 0 5 0 6 0 7 0 8 0 9 0 6 0 7 0 8 0 9 0 7 0 8 0 9 7 8 7 9 8 9 x = 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 7 9 8 9 x = 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 8 9 x = 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 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 p = 2 t = 2 y = 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

### Community Treasure Hunt

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

Start Hunting!