Main Content

getpref

Get custom preference value

Description

prefvalue = getpref(group,pref) returns the value of the specified preference in the specified group. prefvalue can be any MATLAB® data type, including numeric types, character vectors, cell arrays, structures, and objects. If pref specifies multiple preferences, getpref returns the values in a cell array. If the specified preference does not exist, MATLAB returns an error.

example

prefvalue = getpref(group,pref,value) creates the specified preference with the specified default value if the preference does not exist, and then returns that value. If the preference exists, getpref returns the current value.

example

prefvalue = getpref returns all custom groups and preferences as a structure.

Examples

collapse all

Add a preference called version to the mytoolbox group of preferences and then get the preference value.

addpref("mytoolbox","version","1.0")
getpref("mytoolbox","version")
ans =
    '1.0'

Get the value of a preference called name in the mytoolbox group of preferences. Since the preference does not exist, MATLAB creates the preference with the specified value and returns that value.

getpref("mytoolbox","name","My Very Cool Toolbox")
ans =
    'My Very Cool Toolbox'

Input Arguments

collapse all

Custom preference group name, specified as a character vector or a string scalar.

Example: getpref('mytoolbox','version')

Data Types: char | string

Custom preference name, specified as a character vector, a cell array of character vectors, or a string array.

Example: getpref('mytoolbox','version')

Example: getpref('mytoolbox',{'version','modifieddate','docpath'})

Data Types: char | string

Preference value, specified as MATLAB data of any type, including numeric types, character vectors, cell arrays, structures, and objects.

Example: getpref('mytoolbox','version','v1.1.2')

Example: getpref('mytoolbox',{'version','modifieddate','docpath'},{'v1.2.2','09/09/2019','C:\mytoolbox\documentation'})

Version History

Introduced before R2006a