フィルターのクリア

How can I load a saved .mat to restore an app state? (or alternative!)

3 ビュー (過去 30 日間)
Jack Callaghan
Jack Callaghan 2019 年 3 月 5 日
コメント済み: Jack Callaghan 2022 年 5 月 24 日
I am writing an app for some data analysis, and for development reasons I want to be able to load a "saved state" whereby the app object restores to the version in a saved .mat file. My understanding is that it is possible to load a .mat and save fields from it (here, and here), however when I try this the uifigure objects do not become populated. Is there a way to restore an app in the way I have described? Or am I doing something fundamentally wrong?
I am using R2018b and App Designer.
Saving the .mat:
function SaveState(app)
name = inputdlg('Save name:');
save([cd,filesep,name{1},'.mat'],'app')
end
Loading the .mat is referenced in startupFcn:
function app = LoadState(app)
name = uigetfile('*.mat');
opened = load(name);
openf = fields(opened);
for i = 1:numel(openf)
app.(openf{i}) = opened.app.(openf{i});
end
end
  3 件のコメント
Magnus Hök
Magnus Hök 2022 年 5 月 24 日
...also tried:
K>> save('tst','-struct','app')
Error using save
The argument to -STRUCT must be the name of a scalar structure
variable.
K>>
Jack Callaghan
Jack Callaghan 2022 年 5 月 24 日
Hi Magnus.
No, I didn't solve it.
Instead, I created a 'save' function which wrote information to a custom delimited text file, which I can then open using a 'load' function which populates the app. I could link the 'load' function to the app startup but it is more conveient for me to open the app then choose which state to load.

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

回答 (1 件)

Vijaya Lakshmi Chagi
Vijaya Lakshmi Chagi 2019 年 3 月 13 日
The following answer may help you

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by