getpref

Reads a preference stored under a group name.

Category: Environment and Settings > System Commands

Syntax

v = getpref(group, pref)

Returns the value of pref in group; errors if it does not exist.

v = getpref(group, pref, default)

Returns default when the preference does not exist.

s = getpref(group)

Returns a struct with every preference of the group.

Description

Preferences are a small key/value store for user options, organized by group and name. The three-argument form with a default is the usual way to read an option that may not have been saved yet.

Input arguments

group
Group name, usually the name of the program that owns the preferences.
pref
Preference name.
default
Value returned in place of an error when the preference is missing.

Output arguments

v
The stored value, of any type; or a struct when only group is given.

Example

Read with a default

setpref('demoapp', 'count', 7);
disp(getpref('demoapp', 'count'))
disp(getpref('demoapp', 'color', 'blue'))
s = getpref('demoapp')
rmpref('demoapp');
Output
     7
blue
s = struct with fields:

    count: 7
    color: 'blue'

See also

setpref addpref rmpref ispref