-
-
Save anonymous/d630d108a5c684fff264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A = round(1+499.*rand(1,1000)); | |
B = round(501+499.*rand(1,1000)); | |
t = zeros(1000,3); | |
for k=1:300 | |
a = A(1:k); | |
b = B(1:k); | |
% dasdingonesin | |
tic; | |
c = cell2mat(arrayfun(@(x,y) x:y,a,b,'UniformOutput',false)); %#ok<NASGU> | |
t(k,1) = toc; | |
% for loop | |
c = []; | |
tic; | |
for m=1:length(a); | |
c = [c, a(m):b(m)]; %#ok<AGROW> | |
end; | |
t(k,2) = toc; | |
% Luis Mendo | |
tic; | |
m = (0:max(b-a)).'; | |
c = bsxfun(@plus, a, m); | |
mask = bsxfun(@le, m, b-a); | |
c = c(mask).'; | |
t(k,3) = toc; | |
end | |
x = 1:k; | |
plot(x,t(x,1),x,t(x,2),x,t(x,3)); | |
legend('dasdingonesin','for loop','Luis Mendo'); | |
xlabel('Array length'); | |
ylabel('Time [s]'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment