MATLAB Answers

0

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

Asked by MustangManiac on 18 Jul 2019
Latest activity Answered by Abhilash Padma on 24 Jul 2019
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 Comments

Sign in to comment.

1 Answer

Answer by Abhilash Padma on 24 Jul 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

  0 Comments

Sign in to comment.