I save user preferences to a .mat file on disk. Unlike globals, persistents, and get/setappdata, they will survive different sessions of MATLAB, and can even be migrated to a different computer. Plus, if you're on Windows and save them to the C:\Users\Public\AppData\MATLAB folder the results will be the same for all users on a multi-user system, which can be important for consistency. (I've had mixed success storing them where Microsoft want you to, the c:\ProgramData folder.) You may not want different users running your app with different settings for certain parameters, such as filter window size or minimum allowable blob area or whatever, or else they won't get the same answers on the same input data. Of course if you want each user to have their own personal set of parameters, then you can do that too, just store under the user's folder.
I have a LoadUserSettings() function, that gets called when the app launches, and a SaveUserSettings() function that gets called when the user shuts down the app or does some other activity where you want to save it right away, such as changing the folder where their data is or whatever. LoadUserSettings() will read in the mat file, which has the GUI setings, and then use set() to send those gui settings to the proper GUI control/widget. SaveUserSettings() does the opposite, it collects parameters that I want to save from the various controls, and saves a single structure variable that I call UserSettings, to a mat file. UserSettings has different field, like UserSettings.checkboxValue1 and UserSettings.editString1, that hold the different properties of the different controls. But just the ones I want to save - I don't save everything under the sun.
Of course this works perfectly well within a single MATLAB session, like you asked for, but is more robust in that it also works across sessions or even on different computers.
0 Comments
Sign in to comment.