Axes with moving vertical line
20 ビュー (過去 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.
1 件のコメント
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!