Plot time of two different for loops
I have two loops:
for x = 1:100
tic
for n=1:x
#some code
t(n) = toc
开发者_Python百科 end
plot(t)
end
for y = 1:100
tic
for n=1:y
#some code
t(n) = toc
end
plot(t)
end
If I just run one of the for loops and plot the time, it works perfectly. But I if I run both loops and I hold on from first to second series of plotting, I get lots of lines in the graph.
All I want is two graphs representing the two times of the functions plotted.
Here's how I would do it:
t1 = zeros(100*100);
i = 1;
for x = 1:100
tic
for n=1:x
#some code
t1(i) = toc
i = i + 1;
end
end
t2 = zeros(100*100);
i = 1;
for y = 1:100
tic
for n=1:y
#some code
t2(i) = toc
i = i + 1;
end
end
figure();
plot(t1);
hold on;
plot(t2)
精彩评论