// Simon Ayrinhac, IMPMC, Sorbonne Université, (2024) // // permet de sélectionner sur un graphique une série de points // qui se trouve entre 2 clics de l'utilisateur /// // Remarque : il faut une souris à 3 boutons (clics gauche, droite, et molette) // // (Exemple d'utilisation en fin de fichier) function [xout,yout]=Func_xclick_data(x0,y0) tolerance=10; // écart à la droite, règle la zone de points sélectionnée [x,k]=unique(x0); y=y0(k); // Valeurs initialisées ----------------------------- ibutton=3; // clic gauche=3, clic droit=5, clic molette=4 segmentok=10; // initialisation à une valeur quelconque p=1; p0=1; p1=1; // cliquer pour dessiner des morceaux de droite while ibutton~=4 // clic molette=4; disp('En attente du clic de souris...') if ibutton~=4 [ibutton,xcoord,ycoord,iwin,cbmenu]=xclick(); plot(xcoord,ycoord,'+g') // endroit cliqué par l'utilisateur // sélection du point expérimental le plus proche r0=sqrt((xcoord-x).^2+(ycoord-y).^2); xcoord=x(find(r0==min(r0))); ycoord=y(find(r0==min(r0))); if ibutton==3 // fin de segment autorisé, clic droit plot(xcoord,ycoord,'or'); segmentok=1; end if ibutton==5 // clic gauche plot(xcoord,ycoord,'xm') segmentok=0; end xline1(p)=xcoord; yline1(p)=ycoord; if p>1 plot(xline1(p-1:p),yline1(p-1:p),'-r') end segment(p)=segmentok; p=p+1; end end // Nombre de segments -------------------- for q=1:length(x) // on regarde tous les points expérimentaux x0=x(q); y0=y(q); for r=1:length(xline1)-1 if (x0>=xline1(r))&(x0=(yv-tolerance)) //plot(x0,y0,'.r') R1x(p0)=x0; R1y(p0)=y0; R1segment(p0)=segment(r); //plot(x0+Tlaser,y0,'.r') /////////> R2x(p0)=x0+Tlaser; /////////> R2y(p0)=y0; p0=p0+1; p1=p1+1; end //if (y0<=(yv+tolerance))&(y0>=(yv-tolerance)) end //if segment(r)==1 if r<(length(xline1)-1)// on n'interpole pas sur le dernier segment ! if segment(r)==0 // on interpole if interpolation==1 // droite ax+b qui caractérise le segment dx1=xline1(r+1)-xline1(r); dy1=yline1(r+1)-yline1(r); a=dy1/dx1; b=yline1(r)-a.*xline1(r); yv=a*x0+b;// le projeté de y0 sur le segment R1x(p0)=x0; R1y(p0)=yv; R1segment(p0)=segment(r); //plot(x0,yv,'.r') R2x(p0)=x0+Tlaser; R2y(p0)=yv; p0=p0+1; //plot(x0+Tlaser,yv,'.r') end //if interpolation==1 end //if segment(r)==0 // on interpole end //if r<(length(xline1)-1 end //if (x0>=xline1(r))&(x0