How do I save a text field in app designer so that it loads when I restart the app next time?

12 ビュー (過去 30 日間)
MustangManiac
MustangManiac 2019 年 7 月 18 日
コメント済み: venkat ta 2023 年 11 月 9 日
I have a few text boxes in my first app designer app. This are for copying directory path's into for my code to point to. They are working well, but when I close the app the text box defaults back to blank. Some of these paths might not need to change each time I open the app, so I'd prefer them to have whatever was last in them on by default.
I tried doing a 'save' on closing the app but it threw up a warning and didn't work. My idea was to save what was in the boxes and then have that called on the startup funtion.

回答 (1 件)

Abhilash Padma
Abhilash Padma 2019 年 7 月 24 日
Hi,
I understand that you want to get the values assigned for edit fields in previous session as default after reopening the app. My approach is to save the assigned values in a .mat file and use that file after reopening the app. I am implementing two functions ,app.loadState() and app.saveState().
The function app.saveState()saves the values in a .mat file and is called by the UIFigureCloseRequestcallback of UIFigure.
The function app.loadState() assigns the values in a .mat file to the edit fields and is called by the startupFcn callback of UIFigure.
function startupFcn(app)
try
app.loadState;
catch
end
end
% Close request function: UIFigure
function UIFigureCloseRequest(app, event)
app.saveState;
delete(app)
end
function saveState(app)
state.fileEditField.Value = app.fileEditField.Value;
state.locationEditField.Value = app.locationEditField.Value;
save('MyAppDefaultValues.mat','state');
end
function loadState(app)
load('MyAppDefaultValues.mat','state');
app.fileEditField.Value = state.fileEditField.Value;
app.locationEditField.Value = state.locationEditField.Value;
end

カテゴリ

Help Center および File ExchangeDevelop uifigure-Based Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by