How can I connect the points in plot?
조회 수: 3 (최근 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!