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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| function test2
% Ouverture d'une fenetre
% Voir la FAQ pour le DoubleBuffer
% http://matlab.developpez.com/faq/?page=graphiques#graphiques_figure_blink
figure('doublebuffer','on');
% Un tracé
th =linspace(0,4*pi,200);
plot(th,sin(th),'r');
hold on
% Récuparation des limites du graphique
x = xlim;
y = ylim;
% Ajout des deux barres (une bleue et une verte)
% et prise en compte du clic souris avec la propriété ButtonDownFcn
line([x;x],[y(:) y(:)],'linewidth',3,'buttondownfcn',@bdfcn);
% Blocage des limites du graphique
set(gca,'xlimmode','manu')
uicontrol('style','pushbutton',...
'string','Clic',...
'callback',@buttoncb,...
'units','normalized',...
'position',[.05 .05 .1 .1]);
uicontrol('style','edit',...
'string',[],...
'units','normalized',...
'position',[.2 .05 .1 .1]);
function bdfcn(obj,event)
% Fonction a exécuter quand on clique sur une barre
% OBJ : identifiant de la barre sélectionnée
% WindowButtonMotionFcn : fonction à exécuter quand on déplace la souris
% WindowButtonUpFcn : fonction à exécuter quand on relâche la souris
set(gcf,'windowbuttonmotionfcn',{@wbmfcn,obj}, ...
'windowbuttonupfcn',@wbufcn);
function wbmfcn(obj,event,h)
% Fonction à exécuter quand on déplace la souris
% OBJ : identifiant de la fenetre courante
% H : identifiant de la barre sélectionnée
% Modification du pointeur de la souris (juste esthétique)
set(obj,'pointer','fleur');
% Récupération des coordonnées du pointeur de la souris
cp = get(gca,'currentpoint');
% Modification de la position en x de la barre sélectionnée
set(h,'xdata',[cp(1);cp(1)])
function wbufcn(obj,event)
% Fonction à exécuter quand on relâche la souris
set(obj,'windowbuttonmotionfcn',[],'pointer','arrow');
function buttoncb(obj,event)
% Fonction à exécuter quand on clique sur le bouton
% Récupération de l'identigfiant de la barre bleue
h(1) = findobj('type','line','linewidth',3,'color','b');
% Récupération de l'identigfiant de la barre verte
h(2) = findobj('type','line','linewidth',3,'color',[0 .5 0]);
% Récupération des position en x des deux barres
xmin = get(h(1),'xdata');
xmax = get(h(2),'xdata');
% Récupération de l'identifiant de l'objet Edit
h(3) = findobj('type','uicontrol','style','edit');
% Affichage des limites fixées par les deux barres
set(h(3),'string',sprintf('[%.1f %.1f]',xmin(1),xmax(1))) |
Partager