Pass Data between Gui`s
Mostra commenti meno recenti
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 ....
Risposta accettata
Più risposte (3)
Sara
il 4 Ago 2014
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 Commenti
Amit Abhishek,Amit Gupta,Roshan,Sohan,Sunil
il 1 Giu 2017
Perfect answer
iman memarzade
il 27 Dic 2017
Thanks for your perfect answer
Xi Chen
il 9 Mar 2019
Thank you very much! I was looking for this answer for half a day.
Image Analyst
il 9 Mar 2019
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.
Max Müller
il 5 Ago 2014
0 voti
Categorie
Scopri di più su Interactive Control and Callbacks in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!