Documentation

addpref

Add preference

Syntax

addpref('group','pref',val)
addpref('group',{'pref1','pref2',...'prefn'},{val1,val2,...valn})

Description

addpref('group','pref',val)creates the preference specified bygroupandprefand sets its value toval. 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.

grouplabels 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 argumentprefidentifies 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.

Examples

Add a preference calledversionto themytoolboxgroup of preferences, setting its value to the cell array{'1.0','beta'}.

addpref('mytoolbox','version',{'1.0','beta'})

Add a preference calleddocumentationto themytoolboxgroup of preferences, setting its value to a struct you define as having four fields:

mydoc.docexists = 1; mydoc.docpath = fullfile(docroot,'techdoc',... 'matlab_env','examples'); mydoc.demoexists = 1; mydoc.demopath = fullfile(docroot,'techdoc',... 'matlab_env','examples','demo_examples'); addpref('mytoolbox','documentation',mydoc) % 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?