Main Content

setpref

Set custom preference value

Description

example

setpref(group,pref,value)sets the specified preference in the specified group to the specified value. If the preference or group does not exist, MATLAB®creates it.

Preferences are persistent and maintain their values between MATLAB sessions.

Examples

collapse all

Create a preference group and preference and then change the preference value.

Useaddprefto create a preference group calledmytoolboxand add a preference within it calledversion.

addpref('mytoolbox','version','1.0')

Change the value of theversionpreference and then get the preference value.

setpref('mytoolbox','version',{'1.0','beta'}) getpref('mytoolbox','version')
ans = 1×2 cell array {'1.0'} {'beta'}

Input Arguments

collapse all

Custom preference group name, specified as a character vector or a string scalar.groupmust be a valid variable name. For more information, seeVariable 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.prefmust be a valid variable name. For more information, seeVariable Names.

Ifpref是一个单元阵列的性格吗vectors or a non-scalar string,valuemust specify a value for each preference specified inpref.

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. Ifpref是一个单元阵列的性格吗vectors or a nonscalar string array,valuemust specify a value for each preference specified inpref.

Example:1.1

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

Version History

Introduced before R2006a