Cody

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

Solution 1714111

Submitted on 23 Jan 2019 by Martin C.
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; 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 r = 3 B = 6 6 6 0 0 0 0 0 0 B = 6 6 6 3 32 51 0 0 0 B = 6 6 6 3 32 51 -9 -38 -57

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

r = 3 B = -1 1 0 0 0 0 0 0 0 B = -1 1 0 0 -1 1 0 0 0 B = -1 1 0 0 -1 1 1 0 -1

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

r = 7 B = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 B = 0 0 0 0 0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