How set default value in edittext in GUI
1 次查看(过去 30 天)
显示 更早的评论
Hi everyone, I have a problem with my GUI. I have to set default value for edittext (if edittext is empty ---> set variable to double 50 or string 'hello', but if not empty set variable from edittext.I do not know how can i do that. Please help me (Im working on Matlab 2013b or 2015b mac edition)
0 个评论
回答(4 个)
Walter Roberson
2016-5-17
S = get(handles.editbox1, 'string');
if isempty(S)
S = 'hello';
end
1 个评论
Walter Roberson
2016-5-17
http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
And remember it is legal to check isempty() before you do the str2double()
Filip M
2016-5-17
3 个评论
Adam
2016-5-17
编辑:Adam
2016-5-17
You need to show all code relevant to what you are asking. In this case the one line you just added is enough.
And did you not use
guidata( hObject, handles )
at the end of your edit1_Callback? Without this any changes you make to the handles structure in your callback are just local and are lost when the callback scope finishes. So pushbutton1_callback will see exactly the same handles structure as was passed into edit1_callback.
The above code replaces the handles structure stored in the GUI with the one you have edited so that when you trigger the next callback you get the updated 'handles' struct.
Filip M
2016-5-17
3 个评论
Walter Roberson
2016-5-17
I have tested and confirm that if you have not changed the String property of a uicontrol style edit, then applying str2double() to it will result in NaN, which can be caught with isnan() like you show.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!