필터 지우기
필터 지우기

GUI Question: Save user preferences between everytime an application is launched?

조회 수: 1 (최근 30일)
A
A 2016년 3월 5일
답변: Geoff Hayes 2016년 3월 5일
If a GUI requires an input of name or something similar, is it possible to 'save' this so that the next time the application launches, that input is still there?
Thanks

답변 (1개)

Geoff Hayes
Geoff Hayes 2016년 3월 5일
A - when the GUI closes, you can save any data you want to a mat file. See save for details. Then, when the GUI is launched (some time in the future), you can look for that mat file and load the data from it. See the attached for an example which does the following in the OpeningFcn
fileName = 'myGuiData.mat';
if exist(fileName,'file')
data = load(fileName);
username = data.username;
else
username = char(inputdlg('Please enter your name: '));
save(fileName,'username');
end
welcomeStr = ['Welcome ' username '!'];
set(handles.text1,'String',welcomeStr);
In the above, we check for the existence of a file name (the initialization file for the GUI). If it is found, then we load its data and, in particular, the user name. Else, we prompt the user for his or her name and save that result to a file. The user's name is then set in the text control.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by