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:
Matlab UI problem

Subject: Matlab UI problem

From: Aron Sceidt

Date: 7 Dec, 2011 09:50:11

Message: 1 of 4

I am using guide to create a user interface. Amongst other components on the UI I have an axes component, which I am using imshow on to display an image. Is there a way that when the user presses the mouse on the axes I get the coordinate of the image where the user clicked?

Thanks

Subject: Matlab UI problem

From: Nasser M. Abbasi

Date: 7 Dec, 2011 10:06:05

Message: 2 of 4

On 12/7/2011 3:50 AM, Aron Sceidt wrote:
> I am using guide to create a user interface. Amongst other components on the UI I
>have an axes component, which I am using imshow on to display an image. Is
>there a way that when the user presses the mouse on the axes I get the
>coordinate of the image where the user clicked?
>
> Thanks

not sure about the 'image' bit. But you can try

[X,Y] = GINPUT(N) gets N points from the current axes and returns
     the X- and Y-coordinates

--Nasser

Subject: Matlab UI problem

From: Aron Sceidt

Date: 7 Dec, 2011 10:23:09

Message: 3 of 4

Thanks Nasser, my problem however is that the axes is inside a UI amongst other components. I want to create a sort of method that when the user clicks somewhere on those axes (and not anywhere else on the UI) I get the point of the image.. Not sure if I am making myself clear enough.

Thanks


"Nasser M. Abbasi" <nma@12000.org> wrote in message <jbndqc$oaq$1@speranza.aioe.org>...
> On 12/7/2011 3:50 AM, Aron Sceidt wrote:
> > I am using guide to create a user interface. Amongst other components on the UI I
> >have an axes component, which I am using imshow on to display an image. Is
> >there a way that when the user presses the mouse on the axes I get the
> >coordinate of the image where the user clicked?
> >
> > Thanks
>
> not sure about the 'image' bit. But you can try
>
> [X,Y] = GINPUT(N) gets N points from the current axes and returns
> the X- and Y-coordinates
>
> --Nasser

Subject: Matlab UI problem

From: Steven_Lord

Date: 7 Dec, 2011 14:53:51

Message: 4 of 4



"Aron Sceidt" <sigarru87@gmail.com> wrote in message
news:jbneqd$aa$1@newscl01ah.mathworks.com...
> Thanks Nasser, my problem however is that the axes is inside a UI amongst
> other components. I want to create a sort of method that when the user
> clicks somewhere on those axes (and not anywhere else on the UI) I get the
> point of the image.. Not sure if I am making myself clear enough.

SET the image object's ButtonDownFcn property or specify that property when
you create the image. I use the latter technique in the example below.

http://www.mathworks.com/help/techdoc/ref/image_props.html#ButtonDownFcn


function imageClicking

data = imread('ngc6543a.jpg');
image(data, 'ButtonDownFcn', @displayClickedLocation);

function displayClickedLocation(h, ~)

ax = ancestor(h, 'axes');
P = get(ax, 'CurrentPoint');
fprintf('You clicked on x = %g, y = %g.\n', P(1, 1), P(1, 2));


If you're not using a group object (HGGROUP or HGTRANSFORM) in your GUI then
you could replace the first line inside displayClickedLocation with "ax =
get(h, 'Parent');"

http://www.mathworks.com/help/techdoc/creating_plots/f7-40355.html

If you need access to the handles structure inside your ButtonDownFcn, use
GUIDATA.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with 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