I can't get GUI text entry

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 件のコメント

Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2016 年 1 月 12 日
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 2016 年 1 月 12 日
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');

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2016 年 1 月 12 日

0 投票

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 件のコメント

Abdelmoumen Bacetti
Abdelmoumen Bacetti 2016 年 1 月 12 日
It didn't work neither.
Actually, in my original GUI, I have multiple entries that I want put them in a struct-array, that's why I put that W(1).
Abdelmoumen Bacetti
Abdelmoumen Bacetti 2016 年 1 月 12 日
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 ?
Image Analyst
Image Analyst 2016 年 1 月 12 日
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 2016 年 1 月 12 日
of course I'm going use it for something else.
Let me tell you WOW for the set of tutorials

サインインしてコメントする。

カテゴリ

製品

タグ

質問済み:

2016 年 1 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by