reset button gui matlab
Show older comments
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
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
on 30 Apr 2017
Edited: zeyneb khalili
on 30 Apr 2017
Image Analyst
on 30 Apr 2017
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
on 30 Apr 2017
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
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.
Adam
on 2 May 2017
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
on 2 May 2017
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
on 3 May 2017
Edited: zeyneb khalili
on 3 May 2017
Adam
on 3 May 2017
There isn't a magic function to do it all for you, you have to write it.
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
on 3 May 2017
zeyneb khalili
on 3 May 2017
Edited: zeyneb khalili
on 3 May 2017
Adam
on 4 May 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.
Categories
Find more on App Building in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!