这是使用GUIDE的GUI的代码
function varargout = testcreat(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @testcreat_OpeningFcn, ...
'gui_OutputFcn', @testcreat_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
function testcreat_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = testcreat_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function pushbutton1_Callback(hObject, eventdata, handles)
a=get(handles.edit1,'String');
set(handles.text1,'String',a);
guidata(hObject,handles);
我正在尝试在Matlab中构建一个GUI,上面的代码是一个测试。但它不会运行,它会提供错误信息,如:
Attempt to reference field of non-structure array.
Error in testcreat>pushbutton1_Callback (line 104)
a=get(handles.edit1,'String');
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in testcreat (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)testcreat('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
有人知道为什么吗?
答案 0 :(得分:0)
我终于明白了。 ORZ
这是因为我试图通过直接在.fig
文件中操作来使用GUI。如果是这样,数据无法传输。
正确的方法是按下.m
文件中的运行按钮!
希望没有人像我一样做同样愚蠢的事情。