Cody

# Problem 963. We love vectorized solutions. Problem 1 : remove the row average.

Solution 2174701

Submitted on 25 Mar 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   Pass
x = [ 0 1 ; 2 3 ] ; timer=tic; y = remove_average_vectorized(x); duration=toc(timer) % You can probably pass this test with a for loop. assert(duration<0.1,sprintf('Time used %2.3f\n',duration));

m = 0.5000 2.5000 z = 0.5000 0.5000 2.5000 2.5000 duration = 7.0000e-04

2   Fail
x = [ 1:9999 ; 2:10000 ; [ zeros(1,9998) 9999 ] ]; x = repmat(x,1000,1); y_correct = [ -4999:1:4999 ; -4999:1:4999 ; [ repmat(-1,1,9998) 9998 ] ]; y_correct = repmat(y_correct,1000,1); y = remove_average_vectorized(x); assert(isequal(y,y_correct));

m = 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 500...

Matrix dimensions must agree. Error in remove_average_vectorized (line 4) y = x-z; Error in Test2 (line 5) y = remove_average_vectorized(x);

3   Fail
x = [ 1:9999 ; 2:10000 ; [ zeros(1,9998) 9999 ] ]; x = repmat(x,1000,1); timer=tic; y = remove_average_vectorized(x); duration=toc(timer) % A decent vectorized solution should take around 1 second. assert(duration<2,sprintf('Time used %2.3f\n',duration));

m = 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 5000 5001 1 500...

Matrix dimensions must agree. Error in remove_average_vectorized (line 4) y = x-z; Error in Test3 (line 4) y = remove_average_vectorized(x);