Cody

Problem 792. Set some matrix elements to zero

Solution 2737942

Submitted on 24 Jul 2020 by Sarah Daly
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))

row = 3 col = 4 M = 4 i = 4 x = 0 0 0 0 5 5 6 5 7 9 8 3 x = 0 0 0 4 5 5 6 5 7 9 8 3 M = 6 i = 3 x = 0 0 0 4 0 0 0 0 7 9 8 3 x = 0 0 0 4 0 0 6 0 7 9 8 3 M = 9 i = 2 x = 0 0 0 4 0 0 6 0 0 0 0 0 x = 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))

row = 4 col = 4 M = 16 i = 1 x = 0 0 0 0 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 M = 11 i = 2 x = 16 0 0 0 0 0 0 0 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 M = 12 i = 4 x = 16 0 0 0 0 11 0 0 0 0 0 0 4 14 15 1 x = 16 0 0 0 0 11 0 0 0 0 0 12 4 14 15 1 M = 15 i = 3 x = 16 0 0 0 0 11 0 0 0 0 0 12 0 0 0 0 x = 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))

row = 1 col = 1 M = 3.1416 i = 1 x = 0 x = 3.1416

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

row = 1 col = 1 M = 0 i = 1 x = 0 x = 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))

row = 5 col = 5 M = 5 i = 5 x = 0 0 0 0 0 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 M = 4 i = 5 x = 0 0 0 0 5 0 0 0 0 0 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 M = 3 i = 1 x = 0 0 0 0 5 0 0 0 0 4 0 0 0 0 0 4 3 2 1 2 5 4 3 2 1 x = 0 0 0 0 5 0 0 0 0 4 3 0 0 0 0 4 3 2 1 2 5 4 3 2 1 M = 4 i = 1 x = 0 0 0 0 5 0 0 0 0 4 3 0 0 0 0 0 0 0 0 0 5 4 3 2 1 x = 0 0 0 0 5 0 0 0 0 4 3 0 0 0 0 4 0 0 0 0 5 4 3 2 1 M = 5 i = 1 x = 0 0 0 0 5 0 0 0 0 4 3 0 0 0 0 4 0 0 0 0 0 0 0 0 0 x = 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

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

row = 5 col = 5 M = 1 i = 1 x = 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 x = 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 M = 1 i = 1 x = 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 x = 1 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 M = 1 i = 1 x = 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 x = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 M = 1 i = 1 x = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 x = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 1 1 1 M = 1 i = 1 x = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 x = 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))

row = 1 col = 3 M = 9 i = 3 x = 0 0 0 x = 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))

row = 15 col = 2 M = 5 i = 2 x = 0 0 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 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 M = 6 i = 2 x = 0 5 0 0 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 M = 7 i = 2 x = 0 5 0 6 0 0 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 M = 8 i = 2 x = 0 5 0 6 0 7 0 0 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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0 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 M = 8 i = 2 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 0 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 M = 9 i = 2 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 0 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 M = 9 i = 2 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 0 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

Suggested Problems

More from this Author30

Community Treasure Hunt

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

Start Hunting!