MATLAB Answers

Not able to run any GUI related code

5 views (last 30 days)
Hareesha N G
Hareesha N G on 19 Feb 2018
Answered: msahar on 2 Jun 2018
Dear Experts, I am a new learner of MATLAB GUI. I am practicing it using the tutorials available in YOUTUBE.But, I am not able to run any GUI related code in my system.
I am using MATLAB 2012b and Windows-10. MATLAB is custom installed with basic MATLAB only.
Reference to non-existent field 'editl'.
This is the error I get.
Error in ex_2>pushbutton1_Callback (line 151) x = get( handles.editl,'String');
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in ex_2 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)ex_2('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback

  0 Comments

Sign in to comment.

Answers (4)

ES
ES on 19 Feb 2018
I think there is a typing there in line 151.
x = get( handles.edit,'String');
what this line does is, it gets the content from an edit box with tag 'edit' and puts it in x. You have mentioned it as editl.

  0 Comments

Sign in to comment.


Jan
Jan on 19 Feb 2018
Edited: Jan on 19 Feb 2018
dbstop if error
to let Matlab stop, when the error occurs. Then check, why the field is missing:
fieldnames(handles)
According tp the error message there is no field called 'editl'. Most likely there is one with the name 'edit1' - with a one at the end, not a lower-case L.

  0 Comments

Sign in to comment.


Hareesha N G
Hareesha N G on 19 Feb 2018
Sir,
I changed the code using other inputs. But, still not working. I am using GUI for the first time. So, able to find the actual error. Code is attached. Please help me.
Thanks

  3 Comments

Jan
Jan on 19 Feb 2018
Please post only the relevant part of the code and explain "still not work" with any details. Do you get an error message or do the results differ from your expectations?
I assume you mean:
x = get( handles.input_1,'String');
y = get (handles.input_2, 'String') ;
x = str2num(x);
y = str2num(y);
set(handles.output, 'String', x+y);
But what does fail here?
Hareesha N G
Hareesha N G on 19 Feb 2018
Getting the following error when this code is executed.
Error using matlab.ui.Figure/set There is no String property on the Figure class.
Error in ex_2>perform_Callback (line 155) set(handles.output,'String', x+y);
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in ex_2 (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)ex_2('perform_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback
>>
Jan
Jan on 19 Feb 2018
Isn't the error message clear already? handles.output is set to the handle of the figure in this line:
function ex_2_OpeningFcn(hObject, eventdata, handles, varargin)
...
handles.output = hObject;
Then you cannot set its 'String' property, because figures do not have such a property. Only uicontrol objects have them. So check, where you want what to appear and modify this line accordingly:
set(handles.output, 'String', x+y);
By the way: I prefer to set the 'String' property to a string (char vector), not to a number (although this works, at least in modern Matlab versions):
set(handles.otherHandle, 'String', sprintf('%g', x+y));

Sign in to comment.


msahar
msahar on 2 Jun 2018
I guess you do not have ex_2.fig file in your folder. Put ex_2.m and ex_2.fig files in same folder and run it.

  0 Comments

Sign in to comment.

Sign in to answer this question.