MATLAB: Ploting in for loop

I wrote sum which is xs for below calculation There is something wrong with my code below that i can not figure it out?
clc
t=cputime;
k=0;
for p=1:1:7
dt=10^-p;
k=0:1.35/dt;
xs = 2/(sqrt(pi))*sum(exp(-(k*dt).^2)*dt)
e=cputime-t;
semilogx(e,dt)
end

Best Answer

Try this:
k=0;
for p=1:1:7
t=cputime;
dt(p)=10^-p;
k=0:1.35/dt(p);
xs = 2/(sqrt(pi))*sum(exp(-(k*dt(p)).^2)*dt(p))
e(p)=cputime-t;
end
semilogx(1./dt, e)
You were plotting timestep as if it were a consequence of execution time. Also, as p increases, dt decreases, so if you plot dt then it is getting smaller and smaller and so your datapoints were getting further left, which is more difficult for people to understand. If you plot against 1./dt then you are plotting time as a consequence of number of data samples used, which is much more natural for people.
Related Question