addpref
Creates a new preference; fails if it already exists.
Category: Environment and Settings > System Commands
Syntax
addpref(group, pref, val)
Adds preference pref with value val to group.
Description
addpref is the strict way to create a preference: if the name already exists in the group it raises an error instead of overwriting. Use setpref when you want create-or-update behavior.
Input arguments
group- Group name; the group is created if needed.
pref- Preference name.
val- Value to store, of any type.
Example
Create, then try again
addpref('demoapp', 'level', 1);
disp(getpref('demoapp', 'level'))
try
addpref('demoapp', 'level', 2);
catch err
disp(err.message)
end
rmpref('demoapp');
Output
1
A preference with that GROUP and NAME already exists.