I can't get GUI text entry

2 views (last 30 days)
Abdelmoumen Bacetti
Abdelmoumen Bacetti on 12 Jan 2016
hello
_ 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});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%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'))
set(hObject,'BackgroundColor','white');
end
  2 Comments
Sivakumaran Chandrasekaran
when i run this code, it throws error stating, no gui present. mail me the code and gui to siva@photontech.net
Abdelmoumen Bacetti
Abdelmoumen Bacetti on 12 Jan 2016
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.

Answers (1)

Image Analyst
Image Analyst on 12 Jan 2016
It looks okay. The only thing I think might possibly be wrong is the (1). Try using W.name 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.
  4 Comments
Image Analyst
Image Analyst on 12 Jan 2016
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: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
Abdelmoumen Bacetti
Abdelmoumen Bacetti on 12 Jan 2016
of course I'm going use it for something else.
Let me tell you WOW for the set of tutorials

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!