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

 Réponse acceptée

Jan
Jan le 14 Fév 2014

0 votes

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 commentaire

Timothy
Timothy le 15 Fév 2014
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?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by