MATLAB: How to interactively edit a “datatip” displayed on a plot in MATLAB

datatipeditfonthandlesMATLABplotstring

I have created a plot in MATLAB using the PLOT function. I enable the interactive data cursor mode by executing the following command:
datacursormode on
I can now select a point on the plot to display the data values. However, I am unable to select and edit the contents of the "datatip" interactively.

Best Answer

This feature has been added in MATLAB 7.3 (R2006b). It is possible to bring up a callback editor from the data cursor context-menu which allows interactive editing of the data cursor text. You can use the last two items in the Data Cursor context menu, 'Edit Text Update Function' and 'Select Text Update Function,' for this purpose. For previous releases, please read below for workarounds.
To work around this issue, get the handle to the "datatip" and change its 'String' property, as the steps below illustrate:
plot(1:10) % Create Example plot
m = findall(gcf,'Type','hggroup') % Find the handle to the datatip
set(m,'String', 'My String') % Change the "String' property to the desired string to be displayed
The example code above assumes that the "datatip" is the only "hggroup" object present in the figure. If there are more objects of Type "hggroup", then the example will have to be modified to get the handle of the specific "datatip" that you want to edit.