Cody

# Problem 1850. Create a matrix with difference of each row of input matrix

Solution 3942668

Submitted on 1 Dec 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; 7 8 9; 10 40 60;] y_correct = [6 6 6;3 32 51; -9 -38 -57;] assert(isequal(MatDiff(x),y_correct));

x = 1 2 3 7 8 9 10 40 60 y_correct = 6 6 6 3 32 51 -9 -38 -57

Unrecognized function or variable 'x'. Error in MatDiff (line 2) diff([x;x(1,:)]); Error in Test1 (line 3) assert(isequal(MatDiff(x),y_correct));

2   Fail
x = eye(3); y_correct = [ -1 1 0; 0 -1 1; 1 0 -1]; assert(isequal(MatDiff(x),y_correct));

Unrecognized function or variable 'x'. Error in MatDiff (line 2) diff([x;x(1,:)]); Error in Test2 (line 3) assert(isequal(MatDiff(x),y_correct));

3   Fail
x = repmat(7, 7, 7); y_correct = repmat(0, 7, 7); assert(isequal(MatDiff(x),y_correct));

Unrecognized function or variable 'x'. Error in MatDiff (line 2) diff([x;x(1,:)]); Error in Test3 (line 3) assert(isequal(MatDiff(x),y_correct));

4   Fail
x = diag(1:4); y_correct = [ -1 2 0 0; 0 -2 3 0; 0 0 -3 4; 1 0 0 -4;] assert(isequal(MatDiff(x),y_correct));

y_correct = -1 2 0 0 0 -2 3 0 0 0 -3 4 1 0 0 -4

Unrecognized function or variable 'x'. Error in MatDiff (line 2) diff([x;x(1,:)]); Error in Test4 (line 6) assert(isequal(MatDiff(x),y_correct));

### Community Treasure Hunt

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

Start Hunting!