This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.


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, character vectors, 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.


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]

Introduced before R2006a

Was this topic helpful?