Updating edit text fields in gui

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);

 采纳的回答

Jan
Jan 2014-2-14

0 个投票

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.

1 个评论

Thanks Mr. Simon! In my open function i have:
function testgui_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA) % varargin command line arguments to testgui (see VARARGIN)
% Choose default command line output for testgui
handles.output = hObject;
% Update handles structure
b = xlsread('myData.xls');
set(handles.edit1,'String',num2str(b(1)));
set(handles.edit2,'String',num2str(b(2)));
That must be it. The problem is that I need to read in values into the edit text boxes on opening and then be able to change any of the values. Do you know how I may fix it?

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by