【问题标题】:DELETE function is deleting the logo, but I don't want it to delete the logoDELETE 功能正在删除标志,但我不希望它删除标志
【发布时间】:2017-04-05 01:53:06
【问题描述】:

我在 Matlab 中有一个 GUI,其中有一个删除按钮,单击它后,它也会删除其中的徽标。

DELETE函数的代码:

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'));

上传logo的代码(我在matlab中用guide命令做了一个GUI,所以下面这段代码插入到GUI代码里面):

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

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

【问题讨论】:

    标签: matlab user-interface matlab-figure graphical-logo


    【解决方案1】:

    您正在使用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, ...,因为如果我在打开我的 GUI 之前打开一个图形,你会改变我的 other 图形的状态。相反,请使用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)
    

    【讨论】:

    • 我会试试看的。
    • 我试过这段代码,但还是不行,它写的是指定的窗口不存在:figure('Tag', 'Vektorkardiogram')close('Vektorkardiogram')不一定所有的窗口都存在。
    • 你为什么打电话给close('Vektorkardiogram')?这与我写的任何内容都不匹配...
    • close('Vektorkardiogram') 是 6 个可能的图形窗口之一。
    • Vektorkardiogram、P vlna、QRS komplex、T vlna、Roviny:这些是 5 个数字的五个名称,可能会也可能不会被可视化,这些我需要关闭,在 axes10,11 和 12 I加载数据。所以这些东西我需要删除。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 2021-10-12
    • 1970-01-01
    相关资源
    最近更新 更多