MATLAB: Open a .fig and use datatips

2016bMATLAB

I want to save a .fig file and then either I or someone else will open it later, but I want datatips to be available when it is opened later. I can get datacursormode to work when I create the figure, but not after I close it and reopen it.

Best Answer

Abel Babu is correct. If you have created datatips then they will be saved and restored with the figure.
If you have created a dcm object, then it itself will not be saved with the figure. However, if you then call datacursormode() on the figure, then the object that is returned will have the properties of the data cursor object at the time that the figure was saved, including that the UpdateFcn will be restored -- even if the UpdateFcn had been specified as an anonymous function.
If you specifically need to manipulate the dcm object after restoring the figure, then the trick is to use the figure CreateFcn to call datacursormode() to create a new object, which will inherit the old properties; you can then store the dcm object in whatever place you were storing it before.
(Note: if you are using GUIDE, then beware that the handles structure does not exist until after all of the Create functions have been run upon the automatic restoration of the .fig)