Documentation Center

  • Trial Software
  • Product Updates


Add preference




addpref('group','pref',val) creates the preference specified by group and pref and sets its value to val. It is an error to add a preference that already exists. Individual preference values can be any MATLAB® data type, including numeric types, strings, cell arrays, structures, and objects.

group labels a related collection of preferences. You can choose any name that is a legal variable name, and is descriptive enough to be unique, e.g. 'ApplicationOnePrefs'. The input argument pref identifies an individual preference in that group, and must be a legal variable name.

addpref('group',{'pref1','pref2',...'prefn'},{val1,val2,...valn}) creates the preferences specified by the cell array of names 'pref1', 'pref2',...,'prefn', setting each to the corresponding value.

    Note   Preference values are persistent and maintain their values between MATLAB sessions. Where they are stored is system dependent.


Add a preference called version to the mytoolbox group of preferences, setting its value to the cell array {'1.0','beta'}.


Add a preference called documentation to the mytoolbox group of preferences, setting its value to a struct you define as having four fields:

mydoc.docexists = 1;
mydoc.docpath = fullfile(docroot,'techdoc',...
mydoc.demoexists = 1;
mydoc.demopath = fullfile(docroot,'techdoc',...
% Retrieve the preference with GETPREF
p = getpref('mytoolbox','documentation')

p = 
     docexists: 1
       docpath: [1x109 char]
    demoexists: 1
      demopath: [1x123 char]

See Also

| | | | |

Was this topic helpful?