Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

passing data from Gui 1 to Gui 2

조회 수: 1 (최근 30일)
Hamid
Hamid 2015년 12월 3일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Adam
Adam 2015년 12월 4일
편집: Adam 2015년 12월 4일
I use classes to achieve this in what seems to me to be the neatest manner, but if you are not familiar with OOP programming in Matlab and don't want to or have time to learn it then that is an advanced solution. If you create a handle-derived class and pass it from GUI1 to GUI2 then you can access this object in both UIs. The first can set its properties from the inputs of GUI1 and in GUI2 you can add listeners to know when these parameters change.
Other solutions tend to involve using
doc findobj
doc getappdata
doc setappdata
to locate the handle of the second figure and access it's data that way.
I would never recommend this approach and have never used it personally, but I don't have the time to give full code for you using my recommended approach.
Hamid
Hamid 2015년 12월 4일
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

답변 (1개)

Image Analyst
Image Analyst 2015년 12월 3일
Honestly it might be easier if you just combined them into one GUI.
  댓글 수: 3
Image Analyst
Image Analyst 2015년 12월 3일
What doesn't work? In the FAQ it talks about using assignin() and Geoff Hayes solution in an Answers posting. Which did you use? Share your code for it.
Hamid
Hamid 2015년 12월 4일
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

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by