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
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
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
Jose Silva 2018년 7월 3일
Thanks for your answer. Let me better explain how my code is working. When opening the GUI the user will upload two images, and when pressed "match", my function is called and the match of both figures is shown. Below is a sample of the GUI
When the "MATCH OF BOTH IMAGES" appears I want to limit my mouse click to that area and when pressed in the image (axis) I want to get the pixel number (my X and Y) and run the function again with that exactly value which will return two graphics.
I'm a bit noob with matlab, that's why I'm asking for some help.
Regards
Jan
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
Jose Silva 2018년 7월 14일
Sorry @Jan for late response. So, I'm going to try to be simple. I only want to enable the mouse click to the area represented in the picture below, nothing more. The rest I know how to do it.
I don't know if it helps but here is my GUI guide. I'm trying to understand how to use the ButtonDownFcn but I'm not understing how...
Rik
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
Jose Silva 2018년 7월 14일
Thanks Rik. I did it. It is working but now I want to keep the ButtonDownFcn enabled everytime I press in the image. Is it possible?
Rik
Rik 2018년 7월 14일
As long as no function is resetting your axis, the callback will stay enabled.
Jose Silva
Jose Silva 2018년 7월 25일
Something was resetting but I'm calling the callback every time I run my function. It is working.Thank you :D
Jan
Jan 2018년 7월 26일
편집: Jan 2018년 7월 26일
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
Timon Rayis 2019년 11월 5일
where to write the ButtonDownFcn callback?
is it in plot like
plot(.......,'ButtonDownFcn',@somecallback) ?
Jan
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에 대해 자세히 알아보기

질문:

2018년 7월 1일

댓글:

Jan
2019년 11월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by