Main Content

addpref

Add custom preference

Description

example

addpref(group,pref,value) creates the specified preference in the specified group and sets its value to value. If the specified preference exists, MATLAB® returns an error.

Preferences are persistent and maintain their values between MATLAB sessions.

Examples

collapse all

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

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

Add two preferences to the mytoolbox group of preferences and set their values.

addpref('mytoolbox',{'modifieddate','docpath'},{'1/9/2019','C:\mytoolbox\documentation'})

Input Arguments

collapse all

Preference group name, specified as a character vector or a string scalar. group must be a valid variable name. For more information, see Variable Names.

Example: 'mytoolbox'

Data Types: char | string

Custom preference name, specified as a character vector, a cell array of character vectors, or a string array. pref must be a valid variable name. For more information, see Variable Names.

If pref is a cell array of character vectors or a non-scalar string, value must specify a value for each preference specified in pref.

Example: 'version'

Example: {'version','modifieddate','docpath'}

Data Types: char | string

Custom preference value, specified as any MATLAB data type, including numeric types, character vectors, cell arrays, structures, and objects. If pref is a cell array of character vectors or a nonscalar string array, value must specify a cell array that includes a value for each preference specified in pref.

Example: 1.1

Example: {{1.1,'beta'},datetime(2018,1,9),'C:\mytoolbox\documentation'}

Introduced before R2006a