reset button gui matlab

hi i'm using gui matlab and i want to put a reset button i used this instruction (cla(handles.axes1,'reset');) it worked but the axes became visible instead of invisible how can i fix that please any help ?

Answers (1)

cla RESET deletes all objects (including ones with hidden handles)
and also resets all axes properties, except Position and Units, to
their default values.
The default property of 'visible' is 'on' and the default property of 'box' is 'on', so when you use 'reset' then you are asking for those properties to be turned on.
You could try immediately turning those properties off again, but you should consider the possibility that 'reset' is not the right approach for you.

7 Comments

okay now i understand why but do u have any other alternative approach for me ?
Before, when you are initializing:
ax = handles.axes1;
ax.Visible = 'off'; ax.Box = 'off';
ax = props_to_ignore = {'BeingDeleted', 'Legend', 'Parent', 'SubTitle', 'Title', 'Type', 'XAxis', 'YAxis', 'ZAxis'};
handles.ax_setable_properties = setdiff( fieldnames(set(ax)), ax_props_to_ignore);
handles.ax_master_props = get(ax, ax_setable_properties);
guidata(ax, handles);
Then when it is time to do the reset,
cla(handles.axes1);
set(handles.axes1, handles.ax_setable_properties, handles.ax_master_props);
title(handles.axes1, '');
subtitle(handles.axes1, '');
legend(handles.axes1, 'off');
This figures out what properties of axes are settable, takes a copy of the initial values, and stores that away. Then when it is time to reset, it scribbles over the axes properties with the saved values.
Legend information is too complex to be reset by restoring properties; there are cross-links between axes and legend objects that are difficult (or impossible) to manipulate yourself.
Title and Subtitle are not regular properties: they are handles to text objects, and there is too much chance that of recorded text objects have been deleted along the way, so we do not try to clone the text objects and instead zap title and subtitle using commands.
XAxis, YAxis, ZAxis are complex objects, and there are too many things that can go wrong trying to restore them. Let them be handled automatically.
Note: This procedure needs testing for the scenario that you used a polarplot or a time or duration or map plot. I am not certain at the moment that the above code will definitely restore back to a plain numeric axes in that case.
okay thanks it worked for me but i have multiple axes and it worked for one axes only
If handles.axes1 is a vector of axes handles (possible but not recommended), then
%setup -- only needs to be done with respect to one axes, not all of them
ax = handles.axes1(1);
ax.Visible = 'off'; ax.Box = 'off';
ax = props_to_ignore = {'BeingDeleted', 'Legend', 'Parent', 'Position', 'SubTitle', 'Title', 'Type', 'XAxis', 'YAxis', 'ZAxis'};
handles.ax_setable_properties = setdiff( fieldnames(set(ax)), ax_props_to_ignore);
handles.ax_master_props = get(ax, ax_setable_properties);
guidata(ax, handles);
then when it is time to do the reset
%still assuming handles.axes1 is a vector
cla(handles.axes1);
arrayfun(@(ax) set(ax, handles.ax_setable_properties, handles.ax_master_props), handles.axes1)
title(handles.axes1, '');
subtitle(handles.axes1, '');
legend(handles.axes1, 'off');
If you have additional axes to clear then you can use the same setup code, but use
AX = [handles.axes1; handles.axes3]; %just be sure to use ';' between the parts
cla(AX);
arrayfun(@(ax) set(ax, handles.ax_setable_properties, handles.ax_master_props), AX)
title(AX, '');
subtitle(AX, '');
legend(AX, 'off');
Note that the one thing this does not change is the Position of each axes. If you want the reset to restore the "original" position of each axes, then more setup work is needed.
hi it didn't work for me .
i didn't know where to write the set up code and when i wrote only this code
AX = [handles.axes1; handles.axes3]; %just be sure to use ';' between the parts
cla(AX);
arrayfun(@(ax) set(ax, handles.ax_setable_properties, handles.ax_master_props), AX)
title(AX, '');
subtitle(AX, '');
legend(AX, 'off');
in the pushbutton callback it only erases the last action, i mean the last shown image
%setup -- only needs to be done with respect to one axes, not all of them
ax = handles.axes1(1);
ax.Visible = 'off'; ax.Box = 'off';
props_to_ignore = {'BeingDeleted', 'Legend', 'Parent', 'Position', 'SubTitle', 'Title', 'Type', 'XAxis', 'YAxis', 'ZAxis'};
handles.ax_setable_properties = setdiff( fieldnames(set(ax)), ax_props_to_ignore);
handles.ax_master_props = get(ax, ax_setable_properties);
guidata(ax, handles);

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Tags

Asked:

on 11 Apr 2021

Commented:

on 14 Apr 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!