- you only use the handles structure for what it's supppost to (storing handles)
- you retrieve the string at the very moment you need it (ensures that you have the string that is actually shown in the textbox)
How to use 'Edit Text' efficiently in a GUI?
48 views (last 30 days)
I notices that there are two ways to ues it;
The tag of edit1 is edit1.
num1 = get(hObject,'string');
handles.num1 = num1;
guidatda(gcbo,handles); % why need this command?
y = handles.num1;
guidata(gcbo,handles); % why need it too?
y = str2num(get(hObject,handles));
As shown above, what's the difference? And the effect of "guidata(gcbo,handles)" ? Thank you very much!
Arthur on 23 Nov 2012
If you use guidata(gcbo,handles), you save the string of your textbox in the 'handles' structure; in your pshbtn_callback you subsequently read this value from handles again. I personally prefer method 2, where you read out the string of the textbox in the button callback. This has a few advantages:
Method 1 is not wrong though, it will work.