MATLAB Answers


I can't get GUI text entry

Asked by Abdelmoumen Bacetti on 12 Jan 2016
Latest activity Commented on by Abdelmoumen Bacetti on 12 Jan 2016
_ knowing that many people posted the same problem but no working solution has been proposed._
I got this error "Attempt to reference field of non-structure array" when I try get the input from GUI.
I made a simple GUI (edit1 and pushbutton1) in order to see if the problem is from my first GUI then I make necessary corrections.
Unfortunately, I got the same error.
Here is the code of the simple GUI. I didn't change anything in what GUIDE generated except deleting unnecessary comments.
Any thoughts about this.
function varargout = untitled(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
gui_mainfcn(gui_State, varargin{:});
%%opening function
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
%%output function
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
%%push button callback function
function pushbutton1_Callback(hObject, eventdata, handles)
W(1).name = get(handles.edit1,'string');
%%edit textbox callback function
function edit1_Callback(hObject, eventdata, handles)
%%edit textbox create function
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))


when i run this code, it throws error stating, no gui present. mail me the code and gui to
I want add something here. When I debugged the code, I noticed that handles is empty. The line where the error is fired is this one
W(1).name = get(handles.edit1,'string');

Sign in to comment.


1 Answer

Answer by Image Analyst
on 12 Jan 2016

It looks okay. The only thing I think might possibly be wrong is the (1). Try using instead of W(1).name and see if that works. If not, attach both the fig file and m file with the paper clip icon.
By the way, with just that code you've shown, you won't be able to access W once that callback exits.


Show 1 older comment
what do you mean by "with just that code you've shown, you won't be able to access W once that callback exits" ? what should I do more ?
So you just put it into W but never do anything with it afterwards. Do you ever want to use it again? If so, see the FAQ:
of course I'm going use it for something else.
Let me tell you WOW for the set of tutorials

Sign in to comment.