Cody

Problem 45225. generate the matrix

Solution 2089778

Submitted on 12 Jan 2020 by Asif Newaz
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 = 4; y_correct = [0 1 2 3 4; -1 0 1 2 3; -2 -1 0 1 2; -3 -2 -1 0 1; -4 -3 -2 -1 0]; assert(isequal(gen_mat(x),y_correct))

c = -4 -3 -2 -1 0 d = 0 1 2 3 4 y = -4 -3 -2 -1 0 -3 -2 -1 0 1 -2 -1 0 1 2 -1 0 1 2 3 0 1 2 3 4 y = 0 1 2 3 4 -1 0 1 2 3 -2 -1 0 1 2 -3 -2 -1 0 1 -4 -3 -2 -1 0

2   Pass
x = 6; y_correct = [0 1 2 3 4 5 6; -1 0 1 2 3 4 5; -2 -1 0 1 2 3 4; -3 -2 -1 0 1 2 3; -4 -3 -2 -1 0 1 2; -5 -4 -3 -2 -1 0 1; -6 -5 -4 -3 -2 -1 0]; assert(isequal(gen_mat(x),y_correct))

c = -6 -5 -4 -3 -2 -1 0 d = 0 1 2 3 4 5 6 y = -6 -5 -4 -3 -2 -1 0 -5 -4 -3 -2 -1 0 1 -4 -3 -2 -1 0 1 2 -3 -2 -1 0 1 2 3 -2 -1 0 1 2 3 4 -1 0 1 2 3 4 5 0 1 2 3 4 5 6 y = 0 1 2 3 4 5 6 -1 0 1 2 3 4 5 -2 -1 0 1 2 3 4 -3 -2 -1 0 1 2 3 -4 -3 -2 -1 0 1 2 -5 -4 -3 -2 -1 0 1 -6 -5 -4 -3 -2 -1 0

3   Pass
x = 0; y_correct = 0; assert(isequal(gen_mat(x),y_correct))

c = 0 d = 0 y = 0 y = 0

4   Pass
x = []; y_correct = []; assert(isequal(gen_mat(x),y_correct))

c = 1×0 empty double row vector d = 1×0 empty double row vector y = [] y = []