Axes with moving vertical line

20 ビュー (過去 30 日間)
peetman
peetman 2016 年 7 月 14 日
コメント済み: Cedric Bareille 2021 年 3 月 5 日
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

回答 (1 件)

Geoff Hayes
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 件のコメント
Cedric Bareille
Cedric Bareille 2021 年 3 月 5 日
Thanks so much ! This is a very helpful example !

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by