How can I avoid errors related to a datatip when deleting a figure?

5 visualizzazioni (ultimi 30 giorni)
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)

Risposte (1)

Sean de Wolski
Sean de Wolski il 20 Mag 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)
  1 Commento
Matt Butts
Matt Butts il 20 Mag 2022
I am unparenting the panel because I will be using it again (drawing it the first time was quite intensive). I delete the panel later based other user actions.
However, now that you asked this question, maybe just turning the visibility off would work better?

Accedi per commentare.

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by