Matlab 为什么打印句柄总是无效?

Matlab 为什么打印句柄总是无效?,matlab,plot,handle,Matlab,Plot,Handle,我想删除一个绘图及其颜色栏(实际上我想删除绘图中的所有内容,但这几乎是不可能的,请参见) 我这样做: 情节 hplot = pcolor(xAxis, yAxis, Data2D); hcb = colorbar; handles.image.hColorbar = hcb; handles.image.hplot = hplot; guidata(handles.output,handles); 稍后在gui中: if (isfield(handles,'image') &&am

我想删除一个绘图及其颜色栏(实际上我想删除绘图中的所有内容,但这几乎是不可能的,请参见)

我这样做:

情节

hplot = pcolor(xAxis, yAxis, Data2D); 
hcb = colorbar;
handles.image.hColorbar = hcb;
handles.image.hplot = hplot;
guidata(handles.output,handles); 
稍后在gui中:

if (isfield(handles,'image') && isfield(handles.image,'hplot'))
    if (handles.image.hplot~=0)
        delete(handles.image.hplot);
        delete(handles.image.hColorbar);
        handles.image.hplot = 0;
    end
end

它适用于
delete(handles.image.hplot)
,但对于
handles.image.hColorbar
无效的句柄,它会失败-为什么?

此代码段在这里工作正常

通常,建议在两个对象上都检查
ishandle()
,这样就不必设置
handles.image.hplot=0
。由于
delete
已使句柄无效,因此在您为其重新分配新的有效句柄之前,它将永远不会通过
ishandle
检查


如果代码未通过
ishandle()
测试,则表示它已被
删除
,因此无需再次
删除它

这段代码在这里很好用

通常,建议在两个对象上都检查
ishandle()
,这样就不必设置
handles.image.hplot=0
。由于
delete
已使句柄无效,因此在您为其重新分配新的有效句柄之前,它将永远不会通过
ishandle
检查

如果代码未通过
ishandle()
测试,则表示它已被
删除
,因此无需再次
删除它