フィルターのクリア

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

2 ビュー (過去 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 Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by