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 GUI: Define Region of interest

Subject: Matlab GUI: Define Region of interest

From: pascal.steiss@gmx.ch

Date: 19 Oct, 2006 10:00:44

Message: 1 of 8

Hi All

I made a GUI with Matlab - and use the axes object.
Now I would like to define a 'region of interrest' in the data that is
shown in the axes object (-> draw a rectangle with the mouse and get
its coordinates).
Can anyone please tell me how to do something like that?

Pascal

Subject: Matlab GUI: Define Region of interest

From: pascal.steiss@gmx.ch

Date: 19 Oct, 2006 10:53:47

Message: 2 of 8

Ok - I finally found out how to handle Click-Events.
But to define a region of interrest (-> draw a rectangle) I need to get
the button up and button down events.
Does anyone know how to get both?

Pascal

Subject: Matlab GUI: Define Region of interest

From: Jerome

Date: 19 Oct, 2006 14:02:53

Message: 3 of 8

Hi,

help dragrect
 <http://www.mathworks.com/access/helpdesk/help/techdoc/ref/dragrect.html>

Search also for "ROI" in the FEX :

 <http://www.mathworks.com/matlabcentral/fileexchange/loadCategory.do>

Jérôme

Subject: Matlab GUI: Define Region of interest

From: Jeremy Smith

Date: 19 Oct, 2006 17:30:46

Message: 4 of 8

Put 'rbbox' in the WindowButtonDownFcn and use the 'get' command on
the figure to get the 'CurrentPoint'.

Subject: Matlab GUI: Define Region of interest

From: scott smith

Date: 20 Oct, 2006 02:46:53

Message: 5 of 8

Jeremy Smith wrote:
>
>
> Put 'rbbox' in the WindowButtonDownFcn and use the 'get' command on
> the figure to get the 'CurrentPoint'.

Hi Pascal,

You can use the WindowButtonDownFcn and WindowButtonUpFcn callback
functions that are available for figure objects to catch both types
of mouse events. You can create these callbacks in GUIDE by right
clicking over the figure region and selecting callbacks ->
WindowButtonDownFcn.
This will create the callback in your code.

For more info on mouse event programming, see 'MATLAB Advanced GUI
Development' at www.mat-gui.com, may be found
at Amazon.com

Regards,
Scott

Subject: Matlab GUI: Define Region of interest

From: Pascal Steiss

Date: 20 Oct, 2006 08:28:48

Message: 6 of 8

"Scott Smith" schrieb:

> For more info on mouse event programming, see 'MATLAB Advanced GUI
> Development' at www.mat-gui.com, may be found
> at Amazon.com

...bought...

Pascal

Subject: Matlab GUI: Define Region of interest

From: Pascal Steiss

Date: 20 Oct, 2006 08:40:32

Message: 7 of 8

"Jeremy Smith" schrieb:

> Put 'rbbox' in the WindowButtonDownFcn and use the 'get' command on
> the figure to get the 'CurrentPoint'.

I now have the problem: I wrote the EventHandler 'Axes1_ButtonDownFcn' -
but do not get an event when clicking on the axes object.
Any ideas?

BTW: Is there a way to get the ButtonUpFcn Event?
-> At least in the GUI editor, there's no entry for that...

Pascal

Subject: Matlab GUI: Define Region of interest

From: scott smith

Date: 21 Oct, 2006 02:12:42

Message: 8 of 8

Pascal Steiss wrote:
>
>
> "Jeremy Smith" schrieb:
>
>> Put 'rbbox' in the WindowButtonDownFcn and use the 'get'
command
> on
>> the figure to get the 'CurrentPoint'.
>
> I now have the problem: I wrote the EventHandler
> 'Axes1_ButtonDownFcn' -
> but do not get an event when clicking on the axes object.
> Any ideas?
>
> BTW: Is there a way to get the ButtonUpFcn Event?
> -> At least in the GUI editor, there's no entry for that...
>
> Pascal
>

I think you may be calling a plot function that overwrites the
properties of your axes. When you simply call plot( ...), the
function will clear the current axes properties unless you
set(handles.axes1, 'NextPlot', 'ReplaceChildren'). This command will
make sure only child objects in the axes get updated when subsequent
plots are called. Although this means that the axes scale will not
automatically update.

The approach I usually use to handle left/right mouse button events
is to use only the figure's WindowButtonDownFcn and WindowButtonUpFcn
callbacks and create a WindowButtonMotionFcn to track the mouse
position in the figure. You can compare the CurrentPoint mouse
position in the figure with the axes Position property to determine
if the mouse is within the axes region.

Hope this helps ... see page 187 and 188 in MATLAB Advanced GUI
Development for detailed code showing this technique.

scott

PS - there is no ButtonUpFcn for objects, only the WindowButtonUpFcn
for figure objects

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