Callback Problem
Show older comments
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
Accepted Answer
More Answers (1)
Jarrod Rivituso
on 17 Apr 2011
It is strange for me to see code such as
handles.edit1 = val;
in your callback, considering that val is a number you determined seemingly based on user input.
GUIDE starts you off with a handles structure that contains "handles" to each of the uicontrol objects in your GUI. These handles are just unique numbers that are used to identify which uicontrol you are referring to.
When you change the values of these, then the number can no longer be used as an identifier to the uicontrol.
1 Comment
Pietro Rossi
on 19 Apr 2011
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!