How can I connect the points in plot?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Iain
2013-6-11
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)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!