How can I connect the points in plot?

1 view (last 30 days)
Babak
Babak on 11 Jun 2013
Hello everybody, I am writing some program which I have to use FOR loop for drawing the sine function.I would like to plot them continuously,I can't connect the points. Could you help me out?
Thanks.
f=50;
w=2*pi*f;
t1=0.05;
t2=0.1;
alfa=0.7;
for t=0:0.001:pi/15
if t-t1>=0
u1=1;
else
u1=0;
end
if t-t2>=0
u2=1;
else
u2=0;
end
ysag=(1-alfa*(u1-u2))*sin(w*t);
hold on
plot(t,ysag,'b.-')
end

Answers (1)

Iain
Iain on 11 Jun 2013
To draw a line, you need to always supply two points.
Before the loop: t_prior = 0; ysag = 0;
Just before the end:
t_prior = t;
ysag_prior = ysag;
and plot:
plot( [t_prior t], [ysaq_prior ysag],'b')
(Do it with a solid line to start - to prove it works)
  1 Comment
Babak
Babak on 11 Jun 2013
No. It exploit my sinusoidal figure. It makes a vector to each point.My diagram is sinusoidal which is plotted by points.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!