Main Content

getpref

Get custom setting value

Description

prefvalue = getpref(group,pref) returns the value of the specified setting 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 settings, getpref returns the values in a cell array. If the specified setting does not exist, MATLAB returns an error.

example

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

example

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

Examples

collapse all

Add a setting called version to the mytoolbox group of settings and then get the setting value.

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

Get the value of a setting called name in the mytoolbox group of settings. Since the setting does not exist, MATLAB creates the setting 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 setting group name, specified as a character vector or a string scalar.

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

Data Types: char | string

Custom setting 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

Setting 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

expand all