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()
测试,则表示它已被删除
,因此无需再次删除它