I have a graph with several plots, each of them comes from a different source file. I want the data tip to tell me (X,Y) plus the name of the source file. So long my best try (without success) is this:
dcm = datacursormode(gcf);
datacursormode on;
set(dcm,'UpdateFcn',[@myfunction,{SourceFileName}]);
Where myfunction is the default function used in this cases, as pasted at the end of this message and as explained here: http://blogs.mathworks.com/videos/2011/10/19/tutorial-how-to-make-a-custom-data-tip-in-matlab/ Finally, SourceFileName is a string with the name of the source file.
Does anybody knows an easier (or correct) way to do this?
Thanks in advance.
function output_txt = myfunction(~,event_obj)
% Display the position of the data cursor
% obj Currently not used (empty)
% event_obj Handle to event object
% output_txt Data cursor text string (string or cell array of strings).
pos = get(event_obj,'Position');
output_txt = {['X: ',num2str(pos(1),4)],...
['Y: ',num2str(pos(2),4)]};
% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
end
end