How can I avoid errors related to a datatip when deleting a figure?
4 views (last 30 days)
Show older comments
I have a figure that contains an axes with a plot on it. When the figure is closed, I save the plot by setting the axes parant to [] and then deleting the figure.
If a user has clicked on the line to create datatips, the when I delete the figure, I get errors in MATLAB that seem to be related to the datatip. Based on the error messages, I believe these are related to the context menu of the datatip. Is there a way to avoid getting these errors?
I have tried to set the context menu of the data tip, but it seems that property is not settable:
Warning: You cannot set 'ContextMenu' property of DataTip.
I have included a very short sample that demonstrates this:
%% Create a simple plot
f = figure;
p = uipanel(f,'Units','normalized','Position',[0 0 1 1]);
ax = axes(p);
plot(ax,1:10);
%% Interactively create a data tip
%% Delete the figure, but not the panel
p.Parent = [];
delete(f);
This generates the following error:
Warning: Error executing listener callback for PostSet event on UIContextMenu dynamic property in object of matlab.graphics.datatip.DataTip class:
Undefined function 'isvalid' for input arguments of type 'double'.
Error in matlab.graphics.datatip.DataTip/showWarningOnSetUIContextMenu
Error in matlab.graphics.datatip.DataTip>@(obj,evd)hObj.showWarningOnSetUIContextMenu()
Error in matlab.graphics.shape.internal.DataCursorManager/delete
Error in matlab.graphics.shape.internal.DataCursorManager>@(obj,evd)(delete(hObj))
Error in matlab.uitools.internal.uimode/createuimode>localDelete (line 137)
delete(hThis);
Error in matlab.uitools.internal.uimode/createuimode>@(obj,evd)(localDelete(hThis)) (line 18)
hThis.FigureDeleteListener = matlab.ui.internal.createListener(hFig,'ObjectBeingDestroyed',@(obj,evd)(localDelete(hThis)));
> In matlab.graphics.shape.internal/DataCursorManager/delete
In matlab.graphics.shape.internal.DataCursorManager>@(obj,evd)(delete(hObj))
In matlab.uitools.internal.uimode/createuimode>localDelete (line 137)
In matlab.uitools.internal.uimode/createuimode>@(obj,evd)(localDelete(hThis)) (line 18)
0 Comments
Answers (1)
Sean de Wolski
on 20 May 2022
Not sure why you're parenting to [], that doesn't make sense. Just delete the figure with your MWE works fine.
(Still probably a bug that that warning appears)
See Also
Categories
Find more on Graphics Object Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!