How do I save a text field in app designer so that it loads when I restart the app next time?
조회 수: 6 (최근 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 Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!