MATLAB Answers

get(axes,'CurrentPoint') : stack on not-updated current point

30 views (last 30 days)
CurrentPoint definition:
Location of last button click in this Figure. MATLAB sets this property to the location of the pointer at the time of the most recent mouse button press. MATLAB updates this property whenever you press the mouse button while the pointer is in the Figure window.
In addition, MATLAB updates CurrentPoint before executing callback routines defined for the Figure WindowButtonMotionFcn and WindowButtonUpFcn properties. This enables you to query CurrentPoint from these callback routines.
This is the first time I'm trying to use CurrentPoint without a previous click or inside a WindowButtonMotionFcn. And as per definition, the output is relative to the last click on the axes, and not the actual current position. I have wasted 2 hours looking for a solution and this thing is driving me mad. One way could be to calculate manually from groot 'PointerLocation', but having a couple of parent panels makes the calculation a bit off the one provided by CurrentPoint. In addition, if the axes is reversed or rotated somehow, it only gets more difficult. Another way would be to call a java.awt.robot to simulate a click...but looks dirty to me.
What I am looking for is either a direct clean solution to it, or at least a way of firing some hidden events and make matlab update the CurrentPoint property.
Thank you for the support


Sign in to comment.

Accepted Answer

Cam Salzberger
Cam Salzberger on 15 Nov 2018
Edited: Cam Salzberger on 15 Nov 2018
Hello Yury,
If you check out this answer, it answers your question. The documentation (R2018a link)backs it up as well. If you define a WindowButtonMotionFcn callback, the CurrentPoint property of the axes should update with the current position of the mouse cursor. You should be able to either update some other property with the current point within the callback, or just access the current point from wherever necessary.


Yury Arenaccio-Khlebov
Yury Arenaccio-Khlebov on 15 Nov 2018
Thanks for the answer but it is not answering my question. In fact, I started my question just using the definition of the CurrentPoint. I have used CurrentPoint in both modes many time...after a simple ButtonDownFcn callback and with the WindowButtonMotionFcn. Both this function ensure that the CurrentPoint are updated just before the Callback gets executed.
Unfortunately, my new problem is to get the CurrentPoint with another callback...a WindowKeyPressFcn for instance. And the CurrentPoint is not updated as in the conventional use. The only workaround I found for now is to place inside a java robot which instanlty produces a LeftClick and this updates the CurrentPoint that I can use. The KeyPress also triggers a WindowButtonMotionFcn which works just fine as soon as the cursor moves. But I could not fnd a cleaner solution for the first call.
Cam Salzberger
Cam Salzberger on 16 Nov 2018
Hello Yury,
I apoligize if I am misunderstanding something, but I still believe that my suggestion will fulfill your needs. My current understanding of your use-case is to access the current location of the pointer within the axes from the WindowKeyPressFcn callback. My understanding of the CurrentPoint property is that it typically contains the point of the last button click. However, if you define a WindowButtonMotionFcn, the CurrentPoint property should be updated to reflect the location of the pointer within the axes (at least while the pointer is over the axes).
My suggestion was that you define a WindowButtonMotionFcn callback. You shouldn't need to use the callback for anything, just the fact that the callback is triggered when the pointer moves should be enough to update the CurrentPoint whenever the pointer moves across the axes. You can then access the CurrentPoint from your WindowKeyPressFcn callback, and should get the correct value.
There may be some issues with value consistency if you are repeatedly accessing the CurrentPoint property within the other callback, so I'd suggest saving the value to a local variable first, and simply using that variable for the rest of the callback execution.
I hope that this is in-tune with what you are trying to do.
Yury Arenaccio-Khlebov
Yury Arenaccio-Khlebov on 6 Dec 2018
Hi Cam,
Well, I guess I take your advice. It not exaclty the way I imagined the code to work but the result is the same. I am just surprised there is not a way of manually update the current position of an axes, but it happens internally only with specific callbacks.
The way I now changed my code is to set in the beginning and forever a WindowButtonMotionFcn which through another function gets directeded where needed. And at the same time ensures that my current position is always up to date.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by