MATLAB: How to do this in GUI

gui pushbutton

Hi,
I'm trying to get know with GUI. First I'd like to make 2 edit boxes and a pushbutton. The function of this stuff would be that when the user writes some data into the first edit box (can be characters and numeric values also) and hits the pushbutton, the written data should appear in the other edit box. I was wondering that I should write the code under the pushbutton's callback function ? I tried this:
function pushbutton_Callback(hObject, eventdata, handles)
s = get(handles.editbox1, 'String'); if((str2double(get(handles.pushbutton, 'String'))) == 1) set(handles.editbox2, 'String', s); end
What's the problem? Thanks.

Best Answer

so the behavior of the pushbutton_callback() function is to run when the push button is pressed. so you are 99% there. get rid of the if statement and have the function be like
function pushbutton_Callback(hObject, eventdata, handles)
s = get(handles.editbox1, 'String');
set(handles.editbox2, 'String', s);
Since the callback will only run when the pushbutton is pressed there is no need to check the state of the button (unless you set the pushbutton to be a toggle button). if you do need to check the state of the button (ie as a togglebutton) you would use get(hangles.pushbutton,'value'). I'd read the documentation on pushbuttons/uicontrols to double check that last part.