Axes with moving vertical line
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I would like to add two vertical moving lines to the graph and depending on their position it would change the values in the boxes Start and End.
I would also like to do the other way around: by changing the values in the boxes Start and End it would move the vertical lines to the assigned positions.
The lines would be moved by a mouse event.
I have this inside the pushbutton1_Callback
hold on;
plot(x,y);
SP = 20;
line([SP,SP],get(handles.axes1,'Xlim'),'Color','red');
I suppose I would have to create callback events for mouseButtonDown and mouseButtonUp, but I am very new to Matlab and don't know what to put in those callbacks
0 Commenti
Risposte (1)
Geoff Hayes
il 20 Lug 2016
peetman - you will need to include callbacks for the mouse button down, motion, and up events.
set(hFig,'WindowButtonDownFcn', @mouseDown);
set(hFig,'WindowButtonMotionFcn',@mouseMove);
set(hFig,'WindowButtonUpFcn', @mouseUp);
where hFig is the GUI. This way you will be able to capture when the user presses the mouse button down to see if the cursor is near one of your vertical lines, when the user moves the cursor, and when the user releases the button (to end moving the line).
If you save the handles to the lines that you have drawn, then you will be able to update their position as you move the cursor.
See attached for an example.
1 Commento
Vedere anche
Categorie
Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!