share data between guis

Hello,
I am trying to build a main gui and various sub guis to configure some data. This data can be an array. I've seen methods to update handles between guis, but not data.
What would be the best way to achieve this ?
Thanks in advance

4 Commenti

Paulo Silva
Paulo Silva il 25 Feb 2011
There are many ways, one of them is to store the data in the GUI figure UserData like this set(fighandle,'UserData',MyData) and pass the handle of that figure to the second GUI as one argument.
MyData=get(fighandle,'UserData').
You can also use the Tag property instead of sending the handle to the second GUI as argument, set(fighandle,'Tag','MyMainGUI'), and in the other GUIs do MyMainGUI=findobj('type','figure','Tag','MyMainGUI')
MyData=get(MyMainGUI,'UserData').
Joe Nunes
Joe Nunes il 25 Feb 2011
Thank you, I'll give it a try
Walter Roberson
Walter Roberson il 25 Feb 2011
Please see the FAQ,
http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F
Eric
Eric il 10 Gen 2012
My preference (mentioned in the FAQ Walter cites) is to use application data (i.e., getappdata and setappdata). In the comment section at the start of each GUI I keep a list and description of what appdata values are stored.
I would avoid using the UserData property as in the future you may want to store other variables as well. Then you may have to switch from storing an array to storing a structure.
I prefer not to use the handles structure so that this structure always just refers to uicontrol handles.
These are personal preferences and there are a variety of ways to solve the problem, though.
-Eric

Accedi per commentare.

Risposte (3)

Héctor Corte
Héctor Corte il 10 Gen 2012
Another way is to use global variables. But remember to write
global variable_name
in every place you use that variable. For example:
%In this function we set the value of global variable b
function Y=fun1(x,a)
global b
b=a;
Y=a*x
end
%In this function we use the global variable b wich was defined
% on fun1.
function y=fun2(x)
global b
Y=b*x
end

1 Commento

Robert Cumming
Robert Cumming il 10 Gen 2012
globals are generally the wrong way to go - especially if they are so basically named. It is possible for the variable to be changed without your knowledge so it can be hard to trace.

Accedi per commentare.

Alex
Alex il 10 Gen 2012

0 voti

You can achieve this through using matlab Classes. the link above is to a File Exchange example using a class to control a gui.
It's pretty easy to expand the example class from controlling a single GUI to multiple GUI's, and the parent class will contain all of the desired data and easily pass it to the gui's.
David Dapuero
David Dapuero il 13 Mar 2012

0 voti

It´s maybe the closer way to the use of global variables.
Maybe it is a very basic solution and not the best...

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange

Prodotti

Richiesto:

il 25 Feb 2011

Community Treasure Hunt

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

Start Hunting!

Translated by