Broken ButtonDownFcn when used in a class in R2015a

4 views (last 30 days)
I have a class, 'scrollwindow', which uses the axis 'ButtonDownFcn' to get a mouse click and do stuff. My code worked fine until Version 8, but is now broken. The error report is:
Undefined function 'down' for input arguments of type 'matlab.graphics.axis.Axes'.
Here's the relevant code, reduced to its essentials:
methods
function s = scrollwindow(varargin)
...
set(gca, 'ButtonDownFcn', @(src, evt)down(src, evt, s));
...
end
methods (Access = private)
function down(src, evt, s)
...
end
end
end
Any suggestions would be appreciated.

Answers (2)

Etaoin Shrdlu
Etaoin Shrdlu on 28 Aug 2015
"Nevah mind!" I figured it out:
methods
function s = scrollwindow(varargin)
...
set(gca, 'ButtonDownFcn', @(src, evt)down(s));
...
end
end
methods (Access = private)
function down(s)
...
end
end

Steven Lord
Steven Lord on 28 Aug 2015
The reason this used to work is because prior to the introduction of the new graphics system in release R2014b, axes handles were double precision values and user-defined objects take priority over fundamental classes when determining which function or method is called.
With release R2014b, axes handles are now handle objects. Since the src input argument to the ButtonDownFcn is an axes and is left/before the instance of your scrollwindow class, MATLAB will look for a method named down of the axes class. It can't find it, so you receive this error.
Removing the axes handle from your down call is one way to resolve the problem. Changing the relative precedence of the axes class and your scrollwindow class is another.

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!