MATLAB: Callback Problem

callbackguideMATLAB

Hi everyone! I built a simple GUI with GUIDE and edited Callback function. The program is very simple: you can choose from popup-menĂ¹ if copy A to B or B to A. The first time, it works correctly, (i.e A to B or B to A), but if you want to use it again, there is an error, but I don't know why. This is a short part of the program (if you want, i can send you .m and .figure files, my e-mail is pietropp11@gmail.com):
[...]
function edit1_Callback(hObject, eventdata, handles)
val = str2double(get(hObject, 'String'));
if isnan(val)
set(hObject, 'String', 0);
errordlg('Devi inserire un numero','Errore');
end
handles.edit1 = val;
guidata(hObject,handles)
[...]
function edit2_Callback(hObject, eventdata, handles)
val = str2double(get(hObject, 'String'));
if isnan(val)
set(hObject, 'String', 0);
errordlg('Devi inserire un numero','Errore');
end
handles.edit2 = val;
guidata(hObject,handles)
[...]
function pulsante_Callback(hObject, eventdata, handles)
popup = get(handles.popupmenu1, 'Value');
switch popup
case 1
cambio= handles.edit1;
set(handles.edit2, 'String', num2str(cambio));
case 2
cambio= handles.edit2;
set(handles.edit1, 'String', num2str(cambio));
end
[...]
I'm sorry if my English in not very well. Best Regards
Pietro Rossi

Best Answer

Thank you for your answer, but I don't know the solution. What should I do for a simple GUI, i.e., does sum between three numbers? I would two 3 boxes (a,b,c) for number input and 1 text box (d) for the sum, but the first and the second edit (a and b) have to be the same: so if you set a, b==a, and if you set b, a==b. The number you see in the box have to change too. (d==a+b+c)
Thanks a lot for your answer Best Regards
Pietro Rosi