フィルターのクリア

How to create and move a line when I put the mouse on an axes?

7 ビュー (過去 30 日間)
Collegue
Collegue 2019 年 12 月 23 日
コメント済み: J. Alex Lee 2019 年 12 月 23 日
Hello,
I would like to create a line when I colocate the mouse in front of an specific axes for example axes1. When I move though that axes the line has to move with me and when I click I hace to obtain the x position where I am.
Thank you!

回答 (1 件)

J. Alex Lee
J. Alex Lee 2019 年 12 月 23 日
does the built-in matlab function ginput() do what you want?
  4 件のコメント
Collegue
Collegue 2019 年 12 月 23 日
I mean the plotting area
J. Alex Lee
J. Alex Lee 2019 年 12 月 23 日
There are many posts related to this topic, and it's worth your looking through previous Answers that match closely the behavior you are trying to achieve.
One complication is the diverging support of functionality between the classic plotting and the new web-based plotting.
Look for these keywords: WindowButtonMotionFcn, WindowButtonDownFcn, ButtonDownFcn
Minimum working example based on your original question, but it does basically a bit less than what ginput() already does. Hope you find the appropriate snippets in there to customize to your needs.
fig = figure()
ax = axes(fig,'NextPlot','add','XLimMode','manual','YLimMode','manual')
ph = xline(0,'HitTest','off')
fig.WindowButtonMotionFcn = @(o,e)WBMF(o,e,ax,ph)
ax.ButtonDownFcn = @(o,e)BDF(o,e,ax,ph)
function WBMF(this,evnt,ax,ph)
ph.Value = ax.CurrentPoint(1,1);
end
function BDF(this,evnt,ax,ph)
fprintf('clicked at x position: %.2f\n',ax.CurrentPoint(1,1))
end

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

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by