Get mouse coordinates from a specific axis
显示 更早的评论
Hi mates,
I need help with my code. I have a GUI that shows five axis and now I want to get the mouse postion only from one axis. I tried to use the ginput but it returns a value anywhere I click. I was thinking to use the "datacursormode" but I have no idea how to do it. Can someone help me?? I really need to limit the click area to one axis.
Regards
1 个评论
Rik
2018-7-1
Can't you reject the click and call ginput again if the click was outside the axes bounds? (i.e. test the coordinates against the position of the axes object)
回答(1 个)
Jan
2018-7-1
0 个投票
What about using the ButtonDownFcn of the specific axes? What exactly does "get the mouse position" mean? If you explain this, it should be easy to implement the callback function of the ButtonDownFcn.
10 个评论
Jose Silva
2018-7-3
Jan
2018-7-4
What exactly does "I want to limit my mouse click to that area" mean? To which area? "when pressed in the image (axis)": which axes? What is "the pixel number (my X and Y)"? Run which function again?
I recommend to split the problem into pieces and to concentrate on the fist step only to reduce confusion.
Jose Silva
2018-7-14
Rik
2018-7-14
The ButtonDownFcn is executed when you push down a mouse button over the relevant axis. That means that if you click on the axis, this function is executed. It behaves as any other Callback function would. (There is no ClickFcn, so you'll have to use ButtonDownFcn or ButtonUpFcn.)
Many functions (like e.g. imshow) will reset several properties, so you'll have to be careful when using those functions.
Jose Silva
2018-7-14
Rik
2018-7-14
As long as no function is resetting your axis, the callback will stay enabled.
Jose Silva
2018-7-25
As a "high-level" routine plot command clears properties of the axes object. The equivalent "low-level" function line does not do this. If you set the 'NextPlot' property of the axes to 'add', its properties are not cleared by plot anymore. This is done by hold on internally.
Timon Rayis
2019-11-5
where to write the ButtonDownFcn callback?
is it in plot like
plot(.......,'ButtonDownFcn',@somecallback) ?
Jan
2019-11-5
Then either use a local subfunction in the same M-file or create an own M-file called "somecallback.m" which contains the callback function.
类别
在 帮助中心 和 File Exchange 中查找有关 Data Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


