22 lines
415 B
Matlab
22 lines
415 B
Matlab
% create a vector with a random numbers
|
|
x = rand(1000000, 1);
|
|
|
|
fprintf('time needed to manually filter elements smaller than 0.5 in a vector of length %i\n', length(x))
|
|
|
|
tic
|
|
results = [];
|
|
matches = 1;
|
|
for i = 1:length(x)
|
|
if x(i) < 0.5
|
|
results(matches) = x(i);
|
|
matches = matches + 1;
|
|
end
|
|
end
|
|
toc
|
|
|
|
fprintf('\ntime needed to do the same with logical indexing\n')
|
|
|
|
tic
|
|
results = x(x < 0.5);
|
|
toc
|