MATLAB: Updating edit text fields in gui

updating data read into edit text fields

I am building a gui to read data from an excel file into edit fields in my gui. I have a pushbutton to perform calculations using the values read into those edit fields. The problem is that when I change the values in the edit boxes and press the calculate button I get this error:
Error using handle.handle/get
Invalid or deleted object.
Error in testgui>pushbutton1_Callback (line 152)
a = get(handles.edit1,'String');
I would like to do the calculations with the newly entered values and write over the values already stored in the excel file. Please help this small problem is costing me time to complete other aspects of my project. I made a simple calculator gui as an illustration. Thanks in advance!
Example Code:
function pushbutton1_Callback(hObject, eventdata, handles)
a = get(handles.edit1,'String');
b = get(handles.edit2,'String');
xlswrite('myData.xls',[str2num(a) str2num(b)]);
b = xlsread('myData.xls');
set(handles.edit1,'String',b(1));
set(handles.edit2,'String',b(2));
hv = b(1)+b(2);
set(handles.text5,'String',hv);

Best Answer

The error message means, that handles.edit1 does not contain a valid handle. The shown code does not contain code, which could be responsible for overwriting or invalidating the contents of this variable. So look through your code, where this variable is changed.