Pass Data between Gui`s
이전 댓글 표시
Hey Guys, I have created two GUI`s but i dont know how to pass Data between them. Both GUI`s are several m-files.
pls help me ....
채택된 답변
추가 답변 (3개)
Sara
2014년 8월 4일
In GUI_1, store everything you need to share in handles, and call GUI_2 as:
GUI_2(handles)
This may go into a pushbutton callback, i.e. where you want to have GUI_2 appear. In the opening function of GUI_2, you variables will be in varargin{1}.you_var_name. You can now do (in GUI_2 opening function):
handles.myvar1 = varargin{1}.myvar1
to carry around variables from GUI_1 in GUI_2. You could also
The same works from GUI_2 to GUI_1.
댓글 수: 4
Amit Abhishek,Amit Gupta,Roshan,Sohan,Sunil
2017년 6월 1일
Perfect answer
iman memarzade
2017년 12월 27일
Thanks for your perfect answer
Xi Chen
2019년 3월 9일
Thank you very much! I was looking for this answer for half a day.
Image Analyst
2019년 3월 9일
Sharing between multiple GUIs. If the "main" GUI calls other GUIs, then the best way to do it is by passing variables in via the input argument list, and accepting output variables via the output argument list. The output argument of GUI2 can then be sent into GUI3. So someplace in GUI1 (like the callback function of the "Go!" button of GUI1), you'd have this
[out2a out2b out2c] = gui2(in2a, in2b, in2c, in2d);
[out3a out3b] = gui3(out2a, out2b);
or something along those lines. The arguments can be extracted out of the varargin cell array of your opening code for the GUI, for example in the GUI's "OpeningFcn" function if you used GUIDE. Once they are in your opening function, then they can be shared amongst the other functions in the GUI with the methods mentioned earlier in this section. This method will not let GUI1 control GUI2 and GUI3's parameters "live" - they can be changed only when calling the GUIs. To have GUI1 control GUI2 when GUI2 is already running, you can use the assignin() function.
This answer from Geoff Hayes in the Answers forum may also help you in the multiple GUI situation: [3]
Some advice regarding Sara's answer is to use another name for the handle in the second GUI. Call it handles2 or something, not handles
handles2 = varargin{1};
or you may not be able to control the controls in the second GUI because the handles in the first/calling GUI will have been overwritten by this new/incoming handles. For example, if you don't, handles.button1 may refer to the other/called gui's button1, not the gui in this gui's, the calling gui's, button1.
Image Analyst
2014년 8월 6일
0 개 추천
카테고리
도움말 센터 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!