2012-08-09 30 views
1

我想刪除的情節和它的彩條(其實我想刪除一個陰謀的一切,但接縫是幾乎不可能的,見make axes invisible or delete plot completely爲什麼劇情句柄總是無效?

我這樣做:

在情節

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)但沒有FO r handles.image.hColorbar無效句柄 - 爲什麼?

回答

1

這段代碼工作正常,在這裏...

在一般情況下,最好是檢查ishandle()兩個對象,這樣你就不必設置handles.image.hplot = 0。由於delete已使句柄無效,因此它將永遠不會通過ishandle檢查,直到您重新爲其分配新的有效句柄。

如果代碼沒有通過ishandle()測試,則表示已經是deleted,所以再次不需要delete