How do I save a text field in app designer so that it loads when I restart the app next time?
12 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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 Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!