Info

This question is closed. Reopen it to edit or answer.

passing data from Gui 1 to Gui 2

1 view (last 30 days)
Hamid
Hamid on 3 Dec 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi everyone, I have an equation in Gui 2 that contains some inputs.
some of the inputs are entered in Gui 1.
what should I do???
please specify exact code and the right place of that and etc.
because I'm trying to figure out for 5 days and I'm gonna be crazy.
beside I read some answers related to my question and unfortunately doesn't work for me.
THANK YOU GUYS.
  2 Comments
Hamid
Hamid on 4 Dec 2015
I didn't get what you are saying and I will be very thankful if you help me out here. I need this too much.
I don't use assignin() anymore.
This is my code (short version):
m file:
function varargout = GUI_1(varargin)
...
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt = {'Maximum ambient temperature:'};
title = 'General Inputs';
lines = 1;
def = {''};
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
answer=str2double(inputdlg(prompt,title,lines,def,options));
handles.Ta = answer(1);
guidata(hObject,handles)
...
GUI_2 m file:
function varargout = GUI_2(varargin)
...
A=1/Ta;
...
after running, I get this error because I can't pass data from GUI_1 to GUI_2 :
??? Undefined function or variable 'Ta'.
Error in ==> GUI_2>Calculate_Callback at 401
A=1/Ta;
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> GUI_2 at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)GUI_2('Calculate_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

Answers (1)

Image Analyst
Image Analyst on 3 Dec 2015
Honestly it might be easier if you just combined them into one GUI.
  3 Comments
Hamid
Hamid on 4 Dec 2015
I don't use assignin() anymore.
This is my code (short version):
m file:
function varargout = GUI_1(varargin)
...
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject handle to Untitled_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt = {'Maximum ambient temperature:'};
title = 'General Inputs';
lines = 1;
def = {''};
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
answer=str2double(inputdlg(prompt,title,lines,def,options));
handles.Ta = answer(1);
guidata(hObject,handles)
...
GUI_2 m file:
function varargout = GUI_2(varargin)
...
A=1/Ta;
...
after running, I get this error because I can't pass data from GUI_1 to GUI_2 :
??? Undefined function or variable 'Ta'.
Error in ==> GUI_2>Calculate_Callback at 401
A=1/Ta;
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> GUI_2 at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)GUI_2('Calculate_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

Tags

Community Treasure Hunt

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

Start Hunting!