Skip to Main Content Skip to Search
Accelerating the pace of engineering and science

Why is the 'ButtonDownFcn' property of an axes in a GUI not called after I plot a figure in MATLAB 7.3 (R2006b) ?


Date Last Modified: Thursday, June 9, 2011
Solution ID:   1-3K8R2L
Product:   MATLAB
Reported in Release:   R2006b
Platform:   All Platforms
Operating System:   All OS
 

Subject:

Why is the 'ButtonDownFcn' property of an axes in a GUI not called after I plot a figure in MATLAB 7.3 (R2006b) ?

Problem Description:

The 'ButtonDownFcn' property of an axes is defined in the property inspector during the GUI building process.

However, this function is not being called when I run my GUI.

Solution:

High-level plotting functions, by default, clear the axes properties (except the 'position' and the 'units' property).

To prevent calls to PLOT, BAR, etc. from replacing the buttondownfcn, set the 'NextPlot' property of the axes to 'replacechildren' instead of the default 'replace'. This will clear the axes contents and plot the new data without replacing the axes object itself.

If you want to plot data over your existing data, then set the 'NextPlot' property of the axes to 'Add'.

An alternative workaround is to assign 'ButtoDownFcn' for the axes again after calling the plot.


function test()
a=3;
b=4;
h=figure;
plot(rand(3));
axes_handle = gca;
set(axes_handle, 'ButtonDownFcn', {@FcnName,a,b});

function FcnName%(src,evnt,a,b)
disp('click down!!!')
disp(a)
disp(b)

Please provide feedback to help us improve this Solution
Contact support