initialize gui

21 views (last 30 days)
tlawren
tlawren on 2 Nov 2011
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 Comment
tlawren
tlawren on 2 Nov 2011
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.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 2 Nov 2011
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

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 2 Nov 2011
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.

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!