function CustomDataCursor(fh, varargin) % CustomDataCursor Customize data cursor for a figure dcm_obj = datacursormode(fh); set(dcm_obj,'UpdateFcn',{@myupdatefcn}) function txt = myupdatefcn(~,event_obj) % Customizes text of data tips pos = get(event_obj,'Position'); I = get(event_obj, 'DataIndex'); txt = {['X: ',num2str(pos(1))],... ['Y: ',num2str(pos(2))]}; % If there is a Z-coordinate in the position, display it as well if length(pos) > 2 txt{end+1} = ['Z: ',num2str(pos(3))]; end % If the tag field of the selected object is not blank, display it temp = event_obj.Target.Tag; if ~isempty(temp) txt{end+1} = temp; end % If the userdata field is not blank, display it temp = event_obj.Target.UserData; if ~isempty(temp) txt{end+1} = ['T: ' num2str(temp,'%.2f')]; end