Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
identifying which axes ginput returns

Subject: identifying which axes ginput returns

From: Jeff Eriksen

Date: 1 Dec, 2010 01:46:21

Message: 1 of 10

I have a small GUI written with GUIDE to display a 3D dataset in three orthogonial planes. The three views are each in a different axes on the main GUI figure. I can get the local x,y coordinate of a point by using ginput, but I do not know how to tell which of the three axes the point came from.

I have read a bit about the 'CurrentPoint' property, which I might be able to use to get a more global idea of the point's location in the overall figure, but I cannot understand enough to be able to use it, especially within the GUIDE framework.

I have also read about ButtonDownFcn and WindowButtonDownFcn, and HitTest but again, cannot really understand enough to be able to use them in GUIDE.

Any pointers appreciated. Thank in advance.

Subject: identifying which axes ginput returns

From: Sven Holcombe

Date: 2 Dec, 2010 22:02:06

Message: 2 of 10

"Jeff Eriksen" <eriksenj@ohsu.edu> wrote in message <id49dd$kqh$1@fred.mathworks.com>...
> I have a small GUI written with GUIDE to display a 3D dataset in three orthogonial planes. The three views are each in a different axes on the main GUI figure. I can get the local x,y coordinate of a point by using ginput, but I do not know how to tell which of the three axes the point came from.
>
> I have read a bit about the 'CurrentPoint' property, which I might be able to use to get a more global idea of the point's location in the overall figure, but I cannot understand enough to be able to use it, especially within the GUIDE framework.
>
> I have also read about ButtonDownFcn and WindowButtonDownFcn, and HitTest but again, cannot really understand enough to be able to use them in GUIDE.
>
> Any pointers appreciated. Thank in advance.

As the help states:
 GINPUT(N) gets N points from the current axes

Slightly misleading is the fact that the act of clicking inside an axes automatically makes that axes the current axes. Therefore checking the current axes immediately after a call to ginput will tell you the last clicked axes.

So, if I set up a figure with two axes:
figure, ax(1) = subplot(2,1,1), ax(2) = subplot(2,1,2)

Then run ginput() *immediately followed by* getting the current axis:
ginput(1), clickedAx = gca

I can tell which of my two axes were clicked:
 ax==clickedAx

Thanks,
Sven.

Subject: identifying which axes ginput returns

From: Sean de

Date: 2 Dec, 2010 22:18:08

Message: 3 of 10

"Sven Holcombe" <sven.holcombe@gmail.com> wrote in message <id950u$it3$1@fred.mathworks.com>...
> "Jeff Eriksen" <eriksenj@ohsu.edu> wrote in message <id49dd$kqh$1@fred.mathworks.com>...
> > I have a small GUI written with GUIDE to display a 3D dataset in three orthogonial planes. The three views are each in a different axes on the main GUI figure. I can get the local x,y coordinate of a point by using ginput, but I do not know how to tell which of the three axes the point came from.
> >
> > I have read a bit about the 'CurrentPoint' property, which I might be able to use to get a more global idea of the point's location in the overall figure, but I cannot understand enough to be able to use it, especially within the GUIDE framework.
> >
> > I have also read about ButtonDownFcn and WindowButtonDownFcn, and HitTest but again, cannot really understand enough to be able to use them in GUIDE.
> >
> > Any pointers appreciated. Thank in advance.
>
> As the help states:
> GINPUT(N) gets N points from the current axes
>
> Slightly misleading is the fact that the act of clicking inside an axes automatically makes that axes the current axes. Therefore checking the current axes immediately after a call to ginput will tell you the last clicked axes.
>
> So, if I set up a figure with two axes:
> figure, ax(1) = subplot(2,1,1), ax(2) = subplot(2,1,2)
>
> Then run ginput() *immediately followed by* getting the current axis:
> ginput(1), clickedAx = gca
>
> I can tell which of my two axes were clicked:
> ax==clickedAx
>
> Thanks,
> Sven.

That would work unless the click on both axes. Here's a quick wrapper function for ginput that will allow axes to be output as the 4th output argument:

function [x y b ax] = ginputax(n)
%SCd 12/02/2010
    x = zeros(n,1);
    y = x;
    b = x;
    ax = x;
    for ii = 1:n
        [x(ii) y(ii) b(ii)] = ginput(1);
        ax(ii) = gca;
    end
        

Subject: identifying which axes ginput returns

From: Walter Roberson

Date: 2 Dec, 2010 22:26:39

Message: 4 of 10

On 10-12-02 04:02 PM, Sven Holcombe wrote:

> As the help states:
> GINPUT(N) gets N points from the current axes
>
> Slightly misleading is the fact that the act of clicking inside an axes
> automatically makes that axes the current axes. Therefore checking the
> current axes immediately after a call to ginput will tell you the last
> clicked axes.
> So, if I set up a figure with two axes:
> figure, ax(1) = subplot(2,1,1), ax(2) = subplot(2,1,2)
>
> Then run ginput() *immediately followed by* getting the current axis:
> ginput(1), clickedAx = gca
>
> I can tell which of my two axes were clicked:
> ax==clickedAx
>
> Thanks,
> Sven.

"functions that wait for user input (i.e., waitforbuttonpress, waitfor,
ginput)" flush the event queue.

If one clicks on one axis and then on another axis, then the first axis might
be the one used for the input, but it seems to me that the flushing of the
event queue might result in the second axis being selected before ginput()
returns control. I am thus not convinced that a gca "immediately after"
ginput() is guaranteed to return the axis clicked on, and although Sean's
wrapper would reduce the problem, I am currently not convinced that it would
solve the problem.

Subject: identifying which axes ginput returns

From: Jeff Eriksen

Date: 3 Dec, 2010 19:16:06

Message: 5 of 10

"Sven Holcombe" <sven.holcombe@gmail.com> wrote in message <id950u$it3$1@fred.mathworks.com>...
> So, if I set up a figure with two axes:
> figure, ax(1) = subplot(2,1,1), ax(2) = subplot(2,1,2)
>
> Then run ginput() *immediately followed by* getting the current axis:
> ginput(1), clickedAx = gca
>
> I can tell which of my two axes were clicked:
> ax==clickedAx
>
> Thanks,
> Sven.

Sven - thanks, this seems to work well for my application, notwithstanding the further responses by the other responders.
-Jeff

Subject: identifying which axes ginput returns

From: Jeff Eriksen

Date: 3 Dec, 2010 19:20:22

Message: 6 of 10

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <id95v0$l14$1@fred.mathworks.com>...
> That would work unless the click on both axes. Here's a quick wrapper function for ginput that will allow axes to be output as the 4th output argument:
>

Sean - thanks for the additional suggestion. I am not sure what you mean when you write "click on both axes". I can only click on one axis at a time, and I am only obtaining one point and immediately acting upon it. The first replier's suggestion seems to have been sufficient for my purposes, but I will keep yours around if I find I need it.
-Jeff

Subject: identifying which axes ginput returns

From: Jeff Eriksen

Date: 3 Dec, 2010 19:29:07

Message: 7 of 10

Walter Roberson <roberson@hushmail.com> wrote in message <id96f1$2kb$1@canopus.cc.umanitoba.ca>...
>
> If one clicks on one axis and then on another axis, then the first axis might
> be the one used for the input, but it seems to me that the flushing of the
> event queue might result in the second axis being selected before ginput()
> returns control. I am thus not convinced that a gca "immediately after"
> ginput() is guaranteed to return the axis clicked on, and although Sean's
> wrapper would reduce the problem, I am currently not convinced that it would
> solve the problem.

Walter - thanks for the additional comments. As you can see from my response to Sean, it worked for my current application. I appreciate your concerns and will keep them in mind if I run into a more complicated scenario.

This gets me moving forward, but I am still unhappy using ginput. I would really like to be able to continously mouse over any of the three axes and display the mouse position in the appropriate axes coordinates, with my own cross-hairs that only extend to the edges of each axes and not the entire GUI frame. Can someone direct me to more info on this, particularly how to do it in a GUIDE GUI?

-Jeff

Subject: identifying which axes ginput returns

From: Sean de

Date: 3 Dec, 2010 19:46:04

Message: 8 of 10

"Jeff Eriksen" <eriksenj@ohsu.edu> wrote in message <idbftm$4r8$1@fred.mathworks.com>...
> "Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <id95v0$l14$1@fred.mathworks.com>...
> > That would work unless the click on both axes. Here's a quick wrapper function for ginput that will allow axes to be output as the 4th output argument:
> >
>
> Sean - thanks for the additional suggestion. I am not sure what you mean when you write "click on both axes". I can only click on one axis at a time, and I am only obtaining one point and immediately acting upon it. The first replier's suggestion seems to have been sufficient for my purposes, but I will keep yours around if I find I need it.
> -Jeff

If you only need one click then yes that would be sufficient. And yes the crosshairs won't appear outside the current axis. However you CAN click elsewhere and it WILL register where you are. See this example, the y-ranges for the two plots are significantly different, click on both a few times and outside of both a few times.

H1 = subplot(1,2,1);
plot(1:10);
H2 = subplot(1,2,2);
plot(exp(1:10));

[x y b a] = ginputax(4)

Subject: identifying which axes ginput returns

From: Naresh Pai

Date: 3 Dec, 2010 20:51:05

Message: 9 of 10

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <idbhds$en5$1@fred.mathworks.com>...
> "Jeff Eriksen" <eriksenj@ohsu.edu> wrote in message <idbftm$4r8$1@fred.mathworks.com>...
> > "Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <id95v0$l14$1@fred.mathworks.com>...
> > > That would work unless the click on both axes. Here's a quick wrapper function for ginput that will allow axes to be output as the 4th output argument:
> > >
> >
> > Sean - thanks for the additional suggestion. I am not sure what you mean when you write "click on both axes". I can only click on one axis at a time, and I am only obtaining one point and immediately acting upon it. The first replier's suggestion seems to have been sufficient for my purposes, but I will keep yours around if I find I need it.
> > -Jeff
>
> If you only need one click then yes that would be sufficient. And yes the crosshairs won't appear outside the current axis. However you CAN click elsewhere and it WILL register where you are. See this example, the y-ranges for the two plots are significantly different, click on both a few times and outside of both a few times.
>
> H1 = subplot(1,2,1);
> plot(1:10);
> H2 = subplot(1,2,2);
> plot(exp(1:10));
>
> [x y b a] = ginputax(4)

Have you tried getpts() instead?

Naresh

Subject: identifying which axes ginput returns

From: Divakar Roy

Date: 13 Nov, 2012 04:56:17

Message: 10 of 10

"Jeff Eriksen" <eriksenj@ohsu.edu> wrote in message <id49dd$kqh$1@fred.mathworks.com>...
> I have a small GUI written with GUIDE to display a 3D dataset in three orthogonial planes. The three views are each in a different axes on the main GUI figure. I can get the local x,y coordinate of a point by using ginput, but I do not know how to tell which of the three axes the point came from.
>
> I have read a bit about the 'CurrentPoint' property, which I might be able to use to get a more global idea of the point's location in the overall figure, but I cannot understand enough to be able to use it, especially within the GUIDE framework.
>
> I have also read about ButtonDownFcn and WindowButtonDownFcn, and HitTest but again, cannot really understand enough to be able to use them in GUIDE.
>
> Any pointers appreciated. Thank in advance.

I have just uploaded to file-exchange, codes that are supposed to solve the original problem. Here's the link - http://www.mathworks.com/matlabcentral/fileexchange/38997 . Basically it uses BUTTONDOWNFCN, alongwith uipanel. Would appreciate to know if the codes are any help to people still interested in the problem.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us