Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

setpref

Set custom preference value

Syntax

setpref(group,pref,value)

Description

example

setpref(group,pref,value) sets the specified preference to the specified value. If the preference 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.

Use addpref to create a preference group called mytoolbox and add a preference within it called version.

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

Change the value of the version preference.

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

Input Arguments

collapse all

Preference group name, specified as a character vector or a string scalar. group must be a unique and 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 non-scalar string, value must specify 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

Was this topic helpful?