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 32 33 34 35 36 37 38 39 40 41 42 43
| function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
b_selec=get(handles.uipanel1,'SelectedObject');
str=get(b_selec,'String');
cla(handles.axes1)
axis([0 80 0 120])
hold on
% Initially, the list of points is empty.
xy = [];
n = 0;
% Loop, picking up the points.
but = 1;
while but == 1
[xi,yi,but] = ginput(1);
if (xi>=0) && (xi<=80) && (yi>=0) && (yi<=120)
plot(xi,yi,'ro')
n = n+1;
xy(:,n) = [xi;yi];
end
end
t = 1:2;
ts = 1: 0.025: 2;
if strcmp(str,'Segment')
for i=1:n-1
XY(:,40*(i-1)+1:40*(i)+1)=spline([1,2],xy(:,i:i+1),ts);
end
else % if strcmp(str,'Spline')
XY = spline(t,xy,ts);
end
% Plot the interpolated curve.
plot(XY(1,:),XY(2,:),'b-');
assignin('base','XY',XY); |
Partager