1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| clear all
close all
clc
th=0:0.005:2*pi;
y=sin(th);
th_begin = pi/2;
th_end = 3*pi/2;
[pasbesoin,begin_index] = min(abs(th-th_begin));
[pasbesoin,end_index] = min(abs(th-th_end));
fig=figure;
hold on
plot(th,y)
set(fig,'doublebuffer','on')
p=plot(th(1),y(1),'rp');
p1=line([nan nan],[nan nan],'color','green');
xlim([min(th) max(th)])
ylim([min(y) max(y)])
vis = {'off' 'on'};
for n=1:numel(th)
set(p,'xdata',th(n),'ydata',y(n));
v = ((n>begin_index)&(n<end_index)) + 1;
set(p1,'xdata',[th(n) th(n)],'ydata',[-1 y(n)],'visible',vis{v});
drawnow
end |
Partager