Skip to content

getpref

prefs · scripts/prefs/getpref.m

: val = getpref ("group", "pref")
: val = getpref ("group", "pref", default)
: {val1, val2, …} = getpref ("group", {"pref1", "pref2", …})
: prefstruct = getpref ("group")
: prefstruct = getpref ()

Read stored preference values.

Preferences are kept in named groups. getpref ("group", "pref") returns the value stored under pref in group and raises an error if there is none. When default is supplied a missing preference is created with that value and the value is returned, so the call always succeeds.

pref may be a cell array of names; the result is then a cell array of values in the same order, and default, if given, must be a cell array of the same size holding one default per name.

A value may be anything that can be saved: numbers, text, structures, cell arrays or objects.

getpref ("group") returns every preference of the group as a structure, or an empty matrix when the group does not exist. getpref () returns a structure of all groups, each holding its preferences.