Axes with moving vertical line
18 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154866/image.png)
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 个评论
回答(1 个)
Geoff Hayes
2016-7-20
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!