2017-04-04 83 views
0

我有一个GUI在Matlab中,我有一个删除按钮,点击它后,它也删除了它的标志。删除功能是删除标志,但我不希望它删除徽标

用于删除功能的代码:

clc 

figure('Name', 'Vektorkardiogram'); 
%Return handle to figure named 'Vectorcardiogram'. 
h = findobj('Name', 'Vektorkardiogram'); 
close(h); 


figure('Name', 'Roviny'); 
%Return handle to figure named 'Vectorcardiogram'. 
r = findobj('Name', 'Roviny'); 
close(r); 


figure('Name', 'P vlna'); 
%Return handle to figure named 'Vectorcardiogram'. 
p = findobj('Name', 'P vlna'); 
close(p); 


figure('Name', 'QRS komplex'); 
%Return handle to figure named 'Vectorcardiogram'. 
q = findobj('Name', 'QRS komplex'); 
close(q); 


figure('Name', 'T vlna'); 
%Return handle to figure named 'Vectorcardiogram'. 
t = findobj('Name', 'T vlna'); 
close(t); 

arrayfun(@cla,findall(0,'type','axes')); 
delete(findall(findall(gcf,'Type','axe'),'Type','text')); 

用于上载的标志(我已经使用引导命令由GUI在Matlab,所以下面这个代码被插入在GUI代码内)的代码:

logo4 = imread('logo4.png','BackgroundColor',[1 1 1]); 
imshow(logo4) 

拔下DELETE BUTTON,我只想关闭某些图形windwos,而不是删除标志。你能帮我解决吗?

回答

0

您正在使用cla清除所有axes,其中包含您不想删除的徽标。

arrayfun(@cla,findall(0,'type','axes')); 

不是清除一切,最好删除并明确具体对象。

cla(handles.axes10) 
cla(handles.axes11) 

或者,如果你坚持的句柄image对象,你可以忽略轴包含它清除轴

himg = imshow(data); 

allaxes = findall(0, 'type', 'axes'); 
allaxes = allaxes(~ismember(allaxes, ancestor(himg, 'axes'))); 

cla(allaxes) 

还有的时候,你的GUI你不应该永远做findall(0, ...因为如果我在打开图形用户界面之前打开一个图形,则会改变我的其他图的状态。相反,使用findall(gcbf, ...这只会改变你自己的GUI的孩子。要么,要么使用特定于您的GUI的'Tag',然后使用findall来筛选该特定标记。

figure('Tag', 'mygui') 

findall(0, 'Tag', 'mygui') 

更新

您应该使用findall'Name'参数相结合,找出其中的人物确实存在

figs = findall(0, 'Name', 'Vektorkardiogram', ... 
       '-or', 'Name', 'Roviny', ... 
       '-or', 'Name', 'P vlna', ... 
       '-or', 'Name', 'QRS komplex', ... 
       '-or', 'Name', 'T vlna'); 
delete(figs); 

和清除的axes,可以确保他们存在

ax = findall(0, 'tag', 'axes10', '-or', 'tag', 'axes11', '-or', 'tag', 'axes12');  
cla(ax) 
+0

我会试试看。 –

+0

@ john.steak查看更新 – Suever

+0

我曾尝试这个代码,但仍然没有工作,将其写入指定的窗口不存在: '图(“标签”,“Vektorkardiogram”)'' 接近( 'Vektorkardiogram')' 并不总是必须存在所有的窗口。 –