addGroup - Add new settings group - MATLAB (original) (raw)
Syntax
Description
s = addGroup([parentgroup](#mw%5F7eace478-5789-4943-af93-1029bbe4389b),[name](#mw%5F4f938ee7-bfe3-468e-988c-f4b317fedbed))
adds a new settings group to the specified parent settings group and returns aSettingsGroup
object containing the new settings group. By default, settings groups are not hidden, which means that they display in the parent settings group.
s = addGroup(___,[Name,Value](#namevaluepairarguments))
specifies settings group properties using one or more name-value pair arguments. For example, 'Hidden',true
adds a hidden settings group. Specify name-value pairs after all other input arguments.
Examples
Use the settings
function to access the root of the settings tree and then create the settings group mysettings
.
s = settings; newGroup = addGroup(s,"mysettings"); s
s = SettingsGroup with properties:
mysettings: [1×1 SettingsGroup]
mytest: [1×1 SettingsGroup]
matlab: [1×1 SettingsGroup]
Use removeGroup
to remove mysettings
.
removeGroup(s,"mysettings"); s
s = SettingsGroup with properties:
mytest: [1×1 SettingsGroup]
matlab: [1×1 SettingsGroup]
Use the settings
function to access the root of the settings tree and then create the hidden settings group myhiddensettings
. Because the new group is hidden, it does not appear when you display the parent settings group.
s = settings; addGroup(s,"myhiddensettings",Hidden=true); s
s = SettingsGroup with properties:
mytest: [1×1 SettingsGroup]
matlab: [1×1 SettingsGroup]
Although myhiddensettings
does not appear in the settings tree, it is accessible. For example, you can create the settings group myveryhiddensettings
inside myhiddensettings
.
addGroup(s.myhiddensettings,"myveryhiddensettings"); s.myhiddensettings
ans = SettingsGroup 'myhiddensettings' with properties:
myveryhiddensettings: [1×1 SettingsGroup]
You can remove the hidden group in the same way you would a visible group.
removeGroup(s,"myhiddensettings")
Create a settings group and specify a default validation function for the group. This function validates the values of all settings within the group that do not have their own validation functions defined.
Create a validation function numericValidationFcn
that throws an error when the input is not numeric.
function numericValidationFcn(x) errorMsg = "Value must be numeric."; assert(isnumeric(x),errorMsg); end
Use the settings
function to access the root of the settings tree and then create the settings group myNumericSettings
. Specify the validation function.
s = settings; newNumericGroup = addGroup(s,"myNumericSettings",... ValidationFcn=@numericValidationFcn);
If you create a new setting in the myNumericSettings
group and attempt to set the value of the setting to a nonnumeric value, MATLAB errors. For example, MATLAB errors if you run this statement, which attempts to set PersonalValue
to a string instead of a numeric value.
addSetting(newNumericGroup,"mySetting",PersonalValue="Hello")
Use removeGroup
to remove myNumericSettings
.
removeGroup(s,"myNumericSettings");
Input Arguments
Parent settings group to add the group to, specified as aSettingsGroup
object. Use the settings function to access the root settings group object and all the available settings groups.
Name of settings group to add, specified as a character vector or string scalar. If name
already exists in the specified parent settings group, MATLAB® throws an error. MATLAB also errors if name
matches the name of a method of the SettingsGroup object, such as addSetting
orhasGroup
.
Name-Value Arguments
Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN
, where Name
is the argument name and Value
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose Name
in quotes.
Example: addGroup(parentgroup,'myGroup','Hidden',true)
adds a new hidden settings group to the specified parent settings group.
Hidden state, specified as true
orfalse
.
When set to true
, the settings groups and settings within the group do not display, although they remain accessible.
Function to validate settings in the group, specified as a function handle. When specified, the function is used to validate the values of all settings within the group that do not have their own validation functions defined.
The function handle must be associated with a function that accepts the potential setting value as an input argument, has no output arguments, and throws an error if the validation fails.
The function handle must point to a function on the MATLAB path. Anonymous or nested function handles are not supported.
Version History
Introduced in R2019b