reset button gui matlab

I want to add to my gui a reset button that when clicked it clears all inputs data of user. My gui contains edits popupmenu and plots.

Answers (1)

Jan
Jan on 30 Apr 2017

0 votes

You can do this, by adding a button to your GUI which triggers a reset of the values in its callback.
Sorry for this trivial answer. But it is the best answer I can imagine currently. Please post, what you have tried so far and ask a specific question, if a problem occurres. The readers cannot know to which initial values the "popupmenu and plots" should be set. So how can we help you?

14 Comments

zeyneb khalili
zeyneb khalili on 30 Apr 2017
Edited: zeyneb khalili on 30 Apr 2017
Thanks. default value of popupmenu is 0 and axis must be the last value I entered (ex:100) when reset is clicked.
You cannot have a value of 0 for the Value property of a popupmnu control - it will throw an error. If you want, you can make the first string in the popupmenu say 'Please select...' - I do that sometimes. Then to reset, just do
handles.popupmenu1.Value = 1;
We have no idea what "axis must be the last value I entered (ex:100)" means. There is no axis control. There is an axes control however. Maybe axis is a custom field you attached to the handles structure??? No idea. But if it is, you can do
handles.axis = 100;
I want to reset gui as I execute for the first time.
Image Analyst
Image Analyst on 1 May 2017
Edited: Image Analyst on 1 May 2017
It should be. What else would you call it? Why wouldn't your GUI start up the first time with the reset/default condition?
Jan
Jan on 2 May 2017
@zeyneb khalili: It is not clear, what the problem is currently. Please post what you have tried so far an which problems occur.
The simplest way to achieve this is to initialise the state of your GUI in code in the first place rather than in GUIDE.
If you have an function, e.g.
initialise( handles )
that you call in your OpeningFcn then this can do all the work of initialising the state of your UI. Then all you need to do in your reset button is to call this again. It is a bit more work and more 'code clutter' than initialising everything in GUIDE, but it allows resetting much more easily and all that 'code clutter' lets you see the initial state more easily yourself too rather than digging into components in GUIDE.
I'm attaching figfile and mfile of my application.I hope you can help me.
Jan
Jan on 3 May 2017
@zeyneb khalili: We have asked several questions for clarifications, which have not been answered yet. Neither "axis must be the last value I entered (ex:100)" nor "value of popupmenu is 0" is meaningful. Even with the code it is not clear, what you want to achieve.
zeyneb khalili
zeyneb khalili on 3 May 2017
Edited: zeyneb khalili on 3 May 2017
After the execution of my code, some edits or popupmenus will be enabled or empty some won't. I want pushbutton reset to clear and enable all edits and set popupmenus string to 'sélectionnez' and set axis to (0 100).
There isn't a magic function to do it all for you, you have to write it.
Jan
Jan on 3 May 2017
Edited: Jan on 3 May 2017
function RestButtonCallback(hObject, EventData, handles)
handles = guidata(hObject);
handles.popupmenu1.string = {'sélectionnez'};
handles.popupmenu1.value = 1;
handles.axes1.xlim = [0, 100];
end
You see? If you want to set the string of the popup-menu, set the string of the popup-menu and adjust the value also. If you want to set the limits of an axes object, set the limits of an axes object.
Unfortunately you did not provide useful information, so my code is based on pure guessing. Please, zeyneb, give the readers a chance to write a useful answer.
Thanks, what about editbox? should I test if it is not empty and disabled and then I enable and empty it with reset.
zeyneb khalili
zeyneb khalili on 3 May 2017
Edited: zeyneb khalili on 3 May 2017
@Jan Simon @Image Analyst @Adam Thank you all.I appreciate. I did it
As I mentioned above, if you really want to reset to the same state as you initialised to then your best option is to do the full GUI initialisation in the code rather than in GUIDE, then you simply call the same function in both the OpeningFcn and the reset callback.
You also have to consider resetting any underlying data attached to handles or appdata also, but I generally initialise all these to empty in my OpeningFcn (or an function called from it) so these also can go in this common function called from both places.

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Asked:

on 30 Apr 2017

Commented:

on 4 May 2017

Community Treasure Hunt

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

Start Hunting!