MATLAB: Error occur when open from other gui (Error while evaluating uicontrol Callback)

unicontrol

Hi everybody. my problem is my gui calculator works fine but has error when open from other gui.i can open it but the error occur when i press the push button on the calculator. all push button show the same error.
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)
textString = get (handles.answer,'String');
textString = strcat(textString,'2');
set(handles.answer,'String',textString)
the coding for all push button are same except for the push button number. I'm using this coding to open the calculator from other gui.
function calculator_Callback(hObject, eventdata, handles)
% hObject handle to calculator (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
open calculator.fig;
delete(gcbf)
can anyone help me on this problem?thanks

Best Answer

Sam - the error is due to how you are opening your second GUI. The line of code
open calculator.fig;
opens the figure only and does not launch the GUI so all necessary initializations are ignored. Instead, just call the GUI by name (as if you were launching it from the command line) as
function calculator_Callback(hObject, eventdata, handles)
calculator;
close(handles.figure1);
The above assumes that figure1 is the tag for the figure/GUI that you want to close.