Here's some code, that does not work properly. Perhaps somebody knows why? Sometimes the counter miscounts and the performance of "Rotate 3D" decreases, if the number of datatips increases.
function DataTipCounter
% Example Patch Plot
[X,Y] = meshgrid(-2:0.2:2,-2:0.2:2);
Z = X.*exp(-X.^2 - Y.^2);
figure
h = surface(X,Y,Z);
patch(surf2patch(h))
delete(h)
shading faceted; view(3)
% Show figure toolbar
set(gcf,'toolbar','figure');
% Change the texboxes of the datatips
datacursormode on;
cursorMode = datacursormode(gcf);
set(cursorMode,'UpdateFcn',@myfunction)
% Button to switch Datacursormode On/Off
uicontrol('Style','pushbutton','Units','normalized','Position',...
[0.01 0.94 0.2 0.05],'String','Datacursor Switch','Callback','datacursormode',...
'FontUnits','normalized','FontSize',0.4)
function [output_txt, count] = myfunction(~,event_obj)
% obj Currently not used (empty)
% event_obj Handle to event object
% output_txt Data cursor text string (string or cell array of strings).
persistent datatip_objects %handles to the datatips on the graph
n = numel(datatip_objects);
found_match = 0;
count = 0;
%Look for the current datatip in our list of known datatips
while ~found_match && count < n
count = count+1;
found_match = (event_obj == datatip_objects{count});
end
uicontrol('Style','text','Units','normalized','Position',...
[0.79 0.94 0.2 0.05],'String', ['DataTips: ' num2str(count)],...
'FontUnits','normalized','FontSize',0.8)
if found_match
else
datatip_objects{n+1}=event_obj; %this datatip is new, store its handle
end
% Code from the standard 'Update Function'
output_txt = {count};
end
datacursormode off;
end
Thanks in advance