필터 지우기
필터 지우기

CurrentPoint and ButtonDownFcn give different results

조회 수: 3 (최근 30일)
J.S.
J.S. 2018년 7월 11일
답변: J.S. 2018년 7월 12일
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
Walter Roberson
Walter Roberson 2018년 7월 12일
You appear to be using R2014b or later. You should have a look at the newer PickableParts properties.
J.S.
J.S. 2018년 7월 12일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by