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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

2016년 1월 12일

댓글:

2016년 1월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by