I know how to set Preferences in Matlab through GUI buttons,
however, suppose I have different sets of preferences that I would like to switch back and forth between. Is there a way to save a given set of preferences to a file and reload it later?
It looks as though one could build some tools to do something like you're thinking. AFAICT, however, there isn't any prebuilt feature as one would think could be to just swap sets.
in a script or Command Window will show the directory to the preferences that you can then bring up (with File Explorer in Windows recent releases) that you can then manually save to a different directory of your choice. Jan Simon posted a Question (with solution) in that respect several years ago, however that solution no longer works (when I tried it) in more recent releases.
Re-creating these by copying the contents of that ‘back-up’ directory back to the prefdir directory doesn’t always work either, as I unfortunately discovered after (yet another too frequent) recent Windows crash. As dpb notes, I doubt that you could do that programmatically.
It might be (I hope would be) worthwhile to contact MathWorks and submit this as an enhancement request. I (for one) would certainly want that ability, even if only to securely restore existing preferences after a crash.
If you can change the preferences through the command window, consider having Favorite Commands on Quick Access toolbar. There's a shortcut to run command on Q.A. Toolbar (Alt + Number).
Be warned that settings may not actually return the value you're interested in if you haven't previously opened the preferences tab that contains the setting. I learned about this when playing around with Matlab Schemer, but it applies to all settings. Hardly anything is documented, and you need to resort to digging into internals by calling struct on objects. I like that it is possible, but it is in stark contrast with the usual level of documentation. As far as I am aware the com.mathworks.services.Prefs tool has never been properly documented.
Programatic access to preferences is slightly better in Matlab than Octave, but only because there it is next to impossible. I'm planning to include the monstrosity of a function below in my minify function.
function pref=GetMaxLineLengthPref(varargin)
% Retrieve the maximum line length from the editor preferences. This isn't stored this in a
% persistent, in order to allow the user to change this between function calls.
%
% As far as I can tell there is no way to retrieve this programatically for Octave, so the number
% mentioned in the style guide is used ( https://wiki.octave.org/Octave_style_guide ).
%
% This only works if the user has _ever_ opened the preference page. In general not opening the
% preference page will either result in the returned value being 0, or an empty value. For that
% reason a list of default values is included. This list may not be correct or complete, but it
% should be close enough, especially if the user doesn't care enough to have ever opened the
except that I would like to do it programmatically or at least with fewer GUI interactions. There doesn't appear to be a SettingsGroup that handles this, however, nor a QuickAccess option.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
2 Comments
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654723-save-and-load-alternative-sets-of-preferences#comment_1149388
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654723-save-and-load-alternative-sets-of-preferences#comment_1149388
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654723-save-and-load-alternative-sets-of-preferences#comment_1150053
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/654723-save-and-load-alternative-sets-of-preferences#comment_1150053
Sign in to comment.