Clear Filters
Clear Filters

CurrentPoint and ButtonDownFcn give different results

6 views (last 30 days)
Hi,
I have a figure with axes x=8-10 microns, y=30-40 microns. When I click on the figure, in the image region (not the background), and then execute
ax=gca;
ax.CurrentPoint(1,1)
ax.CurrentPoint(1,2)
in the command window, I get two values which are sensible (the first lies between 8 and 10, and the second between 30 and 40). Within my code, I also have the lines
set(myax,'ButtonDownFcn',@CallBackFcn,'HitTest','on')
set(myfig,'ButtonDownFcn',@CallBackFcn,'HitTest','off')
When I run my code and click on (roughly) the same point as before, nothing happens. But, when I click on the background, to the right of the actual image, I get very large values (over 100 for x and a y>40). Can someone explain if my 'HitTest' 's are set incorrectly, and if so, what the proper way is? The callback function used for the axes and the figure is the same. (Note that the labelling of my y axis runs opposite to the traditional way; values at the bottom are greater than those at the top; this is intentional due to the details of my project).
Thanks for your help!
  2 Comments
Walter Roberson
Walter Roberson on 12 Jul 2018
You appear to be using R2014b or later. You should have a look at the newer PickableParts properties.
J.S.
J.S. on 12 Jul 2018
Dear Walter, thank you for the suggestion. I have looked at the documentation page you indicated. The difficulty I am having is that I as the user need to click somewhere within the actual image (not the background) to select a pixel whose data I need to examine. To examine the data, I need to know the coordinates of that pixel relative to the axes. So far, by setting
set(myax,'ButtonDownFcn',@CallBackFcn,'HitTest','on','PickableParts','none')
set(myfig,'ButtonDownFcn',@CallBackFcn,'HitTest','off')
,I can click inside the image itself and get values, but these are unfortunately with respect to the figure window as a whole.
In contrast, if I set
set(myax,'ButtonDownFcn',@CallBackFcn,'HitTest','on','PickableParts','all')
set(myfig,'ButtonDownFcn',@CallBackFcn,'HitTest','off')
then clicking on the image does nothing, clicking on the background gives coordinates with respect to the figure window, and clicking on the axes themselves gives the coordinates of that point on the axis .
Since I really want the coordinates of any point on the image with respect to the axes, can you tell me how this could be achieved? At present, my callback function is as shown:
% function [theX,theY]=CallBackFcn(ax,~)
um_axes=ax;%Get the axes of the figure
theX=um_axes.CurrentPoint(1,1);
theY=um_axes.CurrentPoint(1,2);
end
Thanks for your help. I do appreciate it.

Sign in to comment.

Accepted Answer

J.S.
J.S. on 12 Jul 2018
Thanks for your help, Walter. Using ginput (https://www.mathworks.com/help/matlab/ref/ginput.html) gave me the results I needed.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!