Skip to Main Content Skip to Search
Product 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 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.

Examples

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

addpref('mytoolbox','version',{'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','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]

See Also

getpref | ispref | rmpref | setpref | uigetpref | uisetpref

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS