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

조회 수: 4 (최근 30일)
Matt Butts
Matt Butts 2022년 5월 19일
댓글: Matt Butts 2022년 5월 20일
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)

답변 (1개)

Sean de Wolski
Sean de Wolski 2022년 5월 20일
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
Matt Butts
Matt Butts 2022년 5월 20일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by