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
| fig=figure('Position',[100,100,500,400],'Pointer','fullcrosshair');
axes; grid;
handles.h=0;
guidata(fig,handles);
set(fig,'WindowButtonMotionFcn',@savepoint);
%=========================================================================
function savepoint(obj,eventdata)
handles=guidata(gcbo);
[z1,z2] = ginput(2);
hAxes = get(gcf,'CurrentAxes');
X = get(hAxes,'Xlim');
Y = get(hAxes,'Ylim');
axis([X Y]);
x1 = z1(1);
x2 = z1(2);
y1 = z2(1);
y2 = z2(2);
pente = (y2 - y1)/(x2 - x1);
ordonnee_origine = y1 - pente*x1;
abscisse = X(1):0.001:X(2);
if handles.h~=0 delete(handles.h); end;
h=line(abscisse,pente*abscisse+ordonnee_origine);
S1 = ['pente ',num2str(pente)];
S2 = ['Ordonnee a l''origine ',num2str(ordonnee_origine)];
text(X(2)-(X(2)-X(1))/3,Y(1)+(Y(2)-Y(1))/4,S1,'FontSize',12,'FontWeight','bold','HorizontalAlignment','left',...
'BackGroundColor',[1 1 1]);
text(X(2)-(X(2)-X(1))/3,Y(1)+(Y(2)-Y(1))/6,S2,'FontSize',12,'FontWeight','bold','HorizontalAlignment','left',...
'BackGroundColor',[1 1 1]);
handles.h=h;
guidata(gcbo,handles); |
Partager