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.

답변 (1개)

Jan
Jan 2017년 4월 30일

0 개 추천

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

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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

태그

질문:

2017년 4월 30일

댓글:

2017년 5월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by