This is almost exactly the same as my 'reference' solution. But later some other people came up with cleaner solutions...
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
x = [ 0 1 ; 2 3 ] ;
y_correct = [ -0.5 0.5 ; -0.5 0.5 ] ;
y = remove_average_vectorized(x);
assert(isequal(y,y_correct));
|
2 | 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));
duration =
4.4600e-04
|
3 | Pass |
%%
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));
|
4 | Pass |
%%
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));
duration =
1.2309
|
Make the vector [1 2 3 4 5 6 7 8 9 10]
35569 Solvers
The Hitchhiker's Guide to MATLAB
2874 Solvers
Matrix indexing with two vectors of indices
485 Solvers
Who has power to do everything in this world?
318 Solvers
387 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!