% create a vector with random numbers
x = rand(1000000, 1);

fprintf('Time needed to manually filter out 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
