필터 지우기
필터 지우기

initialize gui

조회 수: 13 (최근 30일)
tlawren
tlawren 2011년 11월 2일
I'm trying to initialize some parameters/data (defaults) in a GUI and I am using a initialization function in the GUI's opening function to do this. This works fine if I wish to use these settings forever, but I need to be able to change them. So far, I haven't figured out how to get my changes stick. The defaults always get reloaded. Is this because my initialization function is in the gui opening function? Is there another way to initialize a gui? Input args to the gui?
  댓글 수: 1
tlawren
tlawren 2011년 11월 2일
EDIT: Basically, I'm developing a little data processing gui that uses saved models to evaluate data and then plot the results. I have default models I want loaded at startup and to do this I'm using an initialization function in the opening function of the gui. (I created the gui using GUIDE) I also need to be able to change the defaults, and to do that, I created a Settings->Change Default Settings top menu that launches a Change Default Settings side gui. Using this side gui, I appear to be able to make the changes I need to make, however, they aren't saved. When I get back to the main gui, I can clearly see that the default settings are still loaded. If I go back to try and change the settings again, the defaults are listed as the loaded settings. I'm not sure what is really happening, but it appears as if my initialization function is being ran after I change the settings, thus undoing the changes I make. I don't know of any other way to load defaults without them always being reloaded.
I don't know if it helps, but I'm passing the main gui's handles structure to my initialization function to set the defaults.

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2011년 11월 2일
What I do is to load a .mat file in the OpeningFcn function. Check to see if it exists first, otherwise set up your defaults ans create the file. Any time you change something, like the folder you're working in, a scroll bar value, a checkbox, or radio button, etc. Update your "UserSettings" structure and save it out to disk. Like
UserSettings.scrollValue = yourScrollBarValue.
save(yourMatFullFileName, 'UserSettings');
Then in your OpeningFcn:
if exist(yourMatFullFileName, 'file')
recalledSettings = load(yourMatFullFileName);
else
% Make up some defaults for UserSettings
UserSettings.fubar = 42; % Whatever.
UserSettings.scrollValue = 0.69; % Whatever.
% Then:
save(yourMatFullFileName, 'UserSettings');
end

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 11월 2일
Do you mean you want your GUI looks like the last time you end your GUI application? That can be done but you have to save your last status into a separate file and then in your GUI opening function, to read those information and set the values.

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by