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

37 visualizaciones (últimos 30 días)
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.

Respuestas (1)

Abhilash Padma
Abhilash Padma el 24 de Jul. de 2019
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

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by