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:
interactive contour plot in gui

Subject: interactive contour plot in gui

From: Daniel

Date: 24 Nov, 2008 18:53:02

Message: 1 of 6

Hello,

I have a gui that displays a contour plot which is updated by other button controls on the same gui. I would like the user to be able to click anywhere on the contour plot to find out the values of the coordinates of that point.

I have tried putting cp=get(hObject, 'CurrentPoint') ; in the contour plot ButtonDownFcn callback but I was unable to retrieve the coordinates after the plot was updated. I tried setting the 'HitTest' property of the contour plot to 'off' after the plot is updated but this does not help.

Any advice would be greatly appreciated!

Thanks in advance!
-Dan

Subject: interactive contour plot in gui

From: matt dash

Date: 24 Nov, 2008 19:56:02

Message: 2 of 6

"Daniel " <djs32@buffalo.edu> wrote in message <gget6e$i0d$1@fred.mathworks.com>...
> Hello,
>
> I have a gui that displays a contour plot which is updated by other button controls on the same gui. I would like the user to be able to click anywhere on the contour plot to find out the values of the coordinates of that point.
>
> I have tried putting cp=get(hObject, 'CurrentPoint') ; in the contour plot ButtonDownFcn callback but I was unable to retrieve the coordinates after the plot was updated. I tried setting the 'HitTest' property of the contour plot to 'off' after the plot is updated but this does not help.
>
> Any advice would be greatly appreciated!
>
> Thanks in advance!
> -Dan

why were you unable to retrieve the coordinates? does it give an error or does it give the wrong coordinates or does the buttondownfcn never run? check the hittest of the axes to make sure it's turned on.

Subject: interactive contour plot in gui

From: Daniel

Date: 24 Nov, 2008 21:22:01

Message: 3 of 6

Thank you for responding to my post Matt.

I have tried HitTest on and off and no matter what I do the ButtonDownFcn callback is not called after plotting. This is the problem; the button click event is never raised.

My gui M-File has the following function (breakpoint on cp line):

function contour_plot_ButtonDownFcn(hObject, eventdata, handles)
cp=get(hObject,'CurrentPoint')

When clicking the contour_plot this event is never stopped at the breakpoint.

Any ideas?

Thanks,
-Dan

Subject: interactive contour plot in gui

From: matt dash

Date: 24 Nov, 2008 22:05:04

Message: 4 of 6

"Daniel " <djs32@buffalo.edu> wrote in message <ggf5tp$bp4$1@fred.mathworks.com>...
> Thank you for responding to my post Matt.
>
> I have tried HitTest on and off and no matter what I do the ButtonDownFcn callback is not called after plotting. This is the problem; the button click event is never raised.
>
> My gui M-File has the following function (breakpoint on cp line):
>
> function contour_plot_ButtonDownFcn(hObject, eventdata, handles)
> cp=get(hObject,'CurrentPoint')
>
> When clicking the contour_plot this event is never stopped at the breakpoint.
>
> Any ideas?
>
> Thanks,
> -Dan

the problem is probably in the order that you're setting properties, because contour is going to reset the axes properties. the following code works:

function test
f=figure;
a=axes;
handles=[];

[X,Y]=meshgrid([1 2 3 4 5],[6 7 8 9]);
Z=X.^2+log(Y);
c=contour(X,Y,Z);
set(a,'buttondownfcn',{@contour_plot_ButtonDownFcn,handles},'hittest','on')


function contour_plot_ButtonDownFcn(hObject, eventdata, handles)
cp=get(hObject,'CurrentPoint')

Subject: interactive contour plot in gui

From: Daniel

Date: 24 Nov, 2008 23:34:02

Message: 5 of 6

Since I am pretty new to Matlab GUI, I have used the GUIDE to create the interface and have not done this programmatically. In the contour_plot properties, I specified '%automatic' in the ButtonDownFcn box and 'HitTest' as on. Also, after plotting the contour every time, I call set(contour_plot,'HitTest',on), to ensure it is set correctly. However, the ButtonDownFcn for the contour plot does not seem to get called. I put a break point in there and it never catches.

Any more suggestions?

Thanks again for your help!

Subject: interactive contour plot in gui

From: Zhelyazko

Date: 25 Nov, 2008 01:44:01

Message: 6 of 6

% you have to hold on the axes otherwise your button down is gone
%if you use plot after that .
% a smart idea is to put buttonDown and on the plot that you are going to plot so
%incase somebody clicks on the line it still gets button down.

function cplot
h=axes('ButtonDownFcn',@getCorAxes,'NextPlot','add');

a=rand(1,200);
pH=plot(a);
set(pH,'ButtonDownFcn',@getCorPlot);

function getCorAxes(varargin)
cordinates=get(gcbo,'CurrentPoint');
display('Axes');
display(cordinates);

function getCorPlot(varargin)
parentH=get(gcbo,'parent');
cordinates=get(parentH,'CurrentPoint');
display('Plot');
display(cordinates);

%other option is to set button down after you plot
function cplot
h=axes();

a=rand(1,200);
pH=plot(h,a);
set(h,'ButtonDownFcn',@getCorAxes);

function getCorAxes(varargin)
cordinates=get(gcbo,'CurrentPoint');
display('Axes');
display(cordinates);

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