I have a GUI in Matlab, where I have a DELETE BUTTON, after I click on it, it as well deletes the logo in it.
The code for the DELETE function:
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'));
The code for uploading the logo (I have made a GUI in Matlab using the guide command, so this code below is inserted inside the GUI code):
logo4 = imread('logo4.png','BackgroundColor',[1 1 1]);
imshow(logo4)
Pusghing the DELETE BUTTON, I just want to close certain figure windwos, not to delete the logo. Could you please help me out?
You are clearing all axes
using cla
which includes the logo that you don't want to delete.
arrayfun(@cla,findall(0,'type','axes'));
Instead of clearing everything, it's better to delete and clear specific objects.
cla(handles.axes10)
cla(handles.axes11)
Alternately, if you keep the handle to the image
object, you can ignore the axes that contains it when clearing axes
himg = imshow(data);
allaxes = findall(0, 'type', 'axes');
allaxes = allaxes(~ismember(allaxes, ancestor(himg, 'axes')));
cla(allaxes)
Also, you shouldn't ever do findall(0, ...
in your GUI because if I open a figure before opening my GUI you will alter the state of my other figure. Instead, use findall(gcbf, ...
which will only alter children of your own GUI. Either that, or use a 'Tag'
specific to your GUI and then use findall
to filter for that specific tag.
figure('Tag', 'mygui')
findall(0, 'Tag', 'mygui')
Update
You should use findall
combined with the 'Name'
parameter to figure out which of your figures actually exists
figs = findall(0, 'Name', 'Vektorkardiogram', ...
'-or', 'Name', 'Roviny', ...
'-or', 'Name', 'P vlna', ...
'-or', 'Name', 'QRS komplex', ...
'-or', 'Name', 'T vlna');
delete(figs);
And for clearing the axes
, you can ensure that they exist
ax = findall(0, 'tag', 'axes10', '-or', 'tag', 'axes11', '-or', 'tag', 'axes12');
cla(ax)