Sharing data between GUIs by application data of root?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I use a couple of GUIs and use setappdata(hGUI1, 'data', data) to store data. To share the handles of one GUI to all other GUIs i use setappdata(0, 'hGUI1', hGUI1).
But, to use the shared data in lets say GUI2, GUI1 needs to be open. Since every GUI use the same data, I want every GUI to work independent from the other GUIs. My idea is to directly use the application data of the root: settapdata(0, 'data', data) and thus make it accessible for every GUI.
But... Is this good idea or does it cause problems I dont see at the moment? Will this method still work with compiled versions of the GUIs? Is there a better way to solve this?
Would appreciate any help or comment - thanks!
Staffan
0 comentarios
Respuesta aceptada
Jan
el 15 de Abr. de 2011
Storing values in the ROOTs ApplicationData or UserData is valid - as long as you do not make any mistakes. Sharing a single object is equivalent to using a GLOBAL variable. As long as you care for correct writing, especially by using a unique name for the variables, everything wents fine.
But is any problems occur, debugging will be much harder. An additional data handling layer can be very helpful then: Create a function, which is responsible for all read and writre operations to these data:
function Data = DataHandler(Command, Data)
switch Command
case 'put'
setappdata(0, 'DataHandler', Data);
case 'get'
Data = getappdata(0, 'DataHandler');
otherwise
error(...)
end
Then setting a single breakpoint inside this function let you observe any change of the "global" variable.
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!