MATLAB: Passing ‘figure_handle’ to ‘datacusormode’ in user-created class.

datacursormodeguide

I have a custom-class that I am using with a GUIDE-generated GUI. I want to create custom data-cursors. However, when I try to pass the axes-object to 'datacursormode(figure_handle)', I get the error 'Invalid figure handle'. My constructor is attached below. Any help is appreciated.
% Constructor
function obj = annotatorGUIClass(rawAxes, psdAxes, allAxes, parentFigure)
obj.rawDataDisplayAxes = rawAxes;
obj.psdDataDisplayAxes = psdAxes;
obj.allPairDisplayAxes = allAxes;
obj.dcmRaw = datacursormode(rawAxes);
obj.dcmPSD = datacursormode(psdAxes);
obj.rawDataDisplayAxes.NextPlot = 'replacechildren';
obj.psdDataDisplayAxes.NextPlot = 'replacechildren';
obj.allPairDisplayAxes.NextPlot = 'replacechildren';
obj.viewMode = 'Raw';
parentFigure.Renderer = 'painters';
end

Best Answer

DATACURSORMODE accepts a figure handle, not an axes handle.
If you want to change the behavior/format based on the axes containing the object on which you clicked, I would use ANCESTOR in the UpdateFcn to find the axes containing the object whose handle is the UpdateFcn's Target input argument and use that to determine which behavior/format to use.