I have two GUI files, which are as follows:
gui1.m
function varargout = gui1(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui1_OpeningFcn, ...
'gui_OutputFcn', @gui1_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 gui1_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = gui1_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function text_Callback(hObject, eventdata, handles)
function text_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.text,'String');
disp(a);
This gui1.m has a edit box and a button, when ever I click on the pushbutton1 it displays the content of it. Now I am trying to do the same with a different GUI interface with the following code.
gui2.m
function varargout = gui2(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui2_OpeningFcn, ...
'gui_OutputFcn', @gui2_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 gui2_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = gui2_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
gui1('pushbutton1_Callback', hObject, eventdata, handles);
so when I click on the button pushbutton1 of gui2.m I get the following error
Reference to non-existent field 'text'.
Error in gui1>pushbutton1_Callback (line 44)
a = get(handles.text,'String');
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in gui1 (line 17)
gui_mainfcn(gui_State, varargin{:});
Error in gui2>pushbutton1_Callback (line 32)
gui1('pushbutton1_Callback', hObject, eventdata,
handles);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in gui2 (line 16)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)gui2('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Could anyone tell me what the problem is? because when i remove the set this and assign some number to variable a in gui1.m and press the button in gui2.m I am able to display the value of a.