Updating application data from several GUI's

Hello
I have a problem in storing appdata to already stored appdata.
I have two GUIs at the moment, this number will increase to one main GUI and several subGUIs.
well back to the problem; in my mainGui i create and store a cell array within the root
setappdata(0, 'hMainGui', gcf);
where the cell array has been stored within the current figure, both actions are made within the mainGuis openingfcn.
Now in the subGui I call the appdata
hMainGui = getappdata(0 , 'hMainGui');
cellArray = getappdata(hMainGui, 'cellArray');
I make a lot of processing of the cellArray after this, where every change in the cellArray is stored within hMainGui
setappdata(hMainGui, 'cellArray', cellArray);
now to the problem part; when this subGui is finished the updated information needs to be stored, such that other gui are able to obtain this information. what I have done so fare, and what isn't working is to set the hMainGui in the root directory again
setappdata(0, 'hMainGui', hMainGui);
My thoughts where that this would update the hMainGui stored in the root directory, but it doesn't. the information stored in the cellArray has not been updated when I call the information later in the process.
any suggestions?
more code can be added if need be.
kind regards
Steffan

 採用された回答

Matt Fig
Matt Fig 2011 年 5 月 5 日

1 投票

Why not just store all needed information in the root?
setappdate(0,'cellarray',cellarray);
then from anywhere else:
cellarray = getappdata(0,'cellarray');
If you need to also store the handle for your GUIs, simply store them in the root also...
setappdata(0,'H_Main_GUI',H_Main_GUI) % GCBF from within Main GUI
You can store as many items as you need in the root's application data. Then these can all be reached from any other GUI.

5 件のコメント

Steffan
Steffan 2011 年 5 月 5 日
it is a solution simply to store all needed data within root, but I imagine a similar problem would occur if I store the data from the first subGui cellArray into the root. Because my idea is to call this data into the next subGui that needs it, and add to the data within the cellArray. Meaning that the cellArray would go from one filled struct to two filleds structs, and then stored in the root again as an *updated* cellArray.
But a solution could be to simply make CellArray1 be the cellArray stored from subGui 1, and cellArray2 be the one stored from subGui 2.
Steffan
Steffan 2011 年 5 月 5 日
it just seems as simpler and easier to overview coding if done as a single cellArray
Steffan
Steffan 2011 年 5 月 5 日
and thank you for the respons
Matt Fig
Matt Fig 2011 年 5 月 5 日
You can still store both the original and updated cellArray values in the root separately, or you can overwrite the original data.
setappdate(0,'cellarray',cellarray); % Original
then later
cellarray = getappdata(0,'cellarray'); % Get original data
% make changes to cellarray in the code ....
setappdate(0,'newcellarray',cellarray); % Store new data.
Now you still have access to both the original and updated. If, instead you want to overwrite the original, just use the same string argument when using SETAPPDATA.
Steffan
Steffan 2011 年 5 月 6 日
thanks Matt !
I'll run with that solution

サインインしてコメントする。

その他の回答 (1 件)

Jarrod Rivituso
Jarrod Rivituso 2011 年 5 月 5 日

0 投票

When you write
setappdata(0, 'hMainGui', hMainGui);
MATLAB is literally just storing a number to the root level object 0. This number is seemingly the handle to what you are calling the main GUI. However, any data associated with the GUI via setappdata is not stored to the root level object, only the handle is stored.
If you don't close the main GUI, then the data should remain persistent. Are you closing the GUI at some point and then reopening it?

1 件のコメント

Steffan
Steffan 2011 年 5 月 5 日
these calls are all made within a subGui
hMainGui = getappdata(0 , 'hMainGui');
cellArray = getappdata(hMainGui, 'cellArray');
setappdata(hMainGui, 'cellArray', cellArray);
setappdata(0, 'hMainGui', hMainGui);
the calls are all part of the callback of a "save & exit" pushbutton, where I close down the subGui, and the idea was that the changes in the cellArray should be stored within appdata.
the mainGui is never closed

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by