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.

Risposte (1)

Jan
Jan il 30 Apr 2017

0 voti

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 Commenti

zeyneb khalili
zeyneb khalili il 30 Apr 2017
Modificato: zeyneb khalili il 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;
zeyneb khalili
zeyneb khalili il 30 Apr 2017
I want to reset gui as I execute for the first time.
Image Analyst
Image Analyst il 1 Mag 2017
Modificato: Image Analyst il 1 Mag 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 il 2 Mag 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.
zeyneb khalili
zeyneb khalili il 2 Mag 2017
I'm attaching figfile and mfile of my application.I hope you can help me.
Jan
Jan il 3 Mag 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 il 3 Mag 2017
Modificato: zeyneb khalili il 3 Mag 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).
Adam
Adam il 3 Mag 2017
There isn't a magic function to do it all for you, you have to write it.
Jan
Jan il 3 Mag 2017
Modificato: Jan il 3 Mag 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.
zeyneb khalili
zeyneb khalili il 3 Mag 2017
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 il 3 Mag 2017
Modificato: zeyneb khalili il 3 Mag 2017
@Jan Simon @Image Analyst @Adam Thank you all.I appreciate. I did it
Adam
Adam il 4 Mag 2017
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.

Accedi per commentare.

Categorie

Scopri di più su App Building in Centro assistenza e File Exchange

Richiesto:

il 30 Apr 2017

Commentato:

il 4 Mag 2017

Community Treasure Hunt

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

Start Hunting!

Translated by