Main Content

addSetting

Add new factory setting

Description

example

s = addSetting(parentgroup,name) adds the factory setting name to the specified parent factory group and returns the new setting as a FactorySetting. By default, factory settings are hidden, which means that they do not display in the parent settings group.

example

s = addSetting(___,Name,Value) specifies the factory setting properties using one or more name-value pair arguments. For example, 'Hidden',false creates a factory setting that is visible in the factory settings tree. Specify name-value pairs after all other input arguments.

Examples

collapse all

Create the root factory group for the toolbox mytoolbox and then add a new setting to the tree.

Create the root factory group mytoolbox.

myToolboxFactoryTree = matlab.settings.FactoryGroup.createToolboxGroup('mytoolbox', ...
    'Hidden',false);

Add the setting FontSize and give it a value.

fontSizeSetting = addSetting(myToolboxFactoryTree,'FontSize','FactoryValue',11,'Hidden',false);

Create a setting and specify a function to validate its value.

First, 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

Create the root factory group mytoolbox.

myToolboxFactoryTree = matlab.settings.FactoryGroup.createToolboxGroup('mytoolbox', ...
    'Hidden',false);

Add the setting FontSize and specify the validation function numericValidationFcn.

addSetting(myToolboxFactoryTree,'FontSize','FactoryValue',11,'Hidden',false, ...
    'ValidationFcn',@numericValidationFcn);

MATLAB® throws an error whenever the setting is set to a nonnumeric value.

Input Arguments

collapse all

Parent factory group to add the setting to, specified as a FactoryGroup object. Use the matlab.settings.FactoryGroup.createToolboxGroup function to create the root factory group object.

Example: addSetting(s.mytoolbox,'newSetting')

Name of factory setting to add, specified as a character vector or string. If the factory setting name exists in the specified parent group, MATLAB displays an error.

Example: addGroup(parentGroup,'newSetting')

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: addSetting(parentGroup,'newGroup','Hidden',false) creates a visible factory group.

Factory value of setting, specified as MATLAB data of any type except for handle types. Data containers such as cell arrays, structs, and objects that include handles are also not supported. You must specify either a factory value or a factory value function for the setting, but not both.

Function to set the setting factory value, specified as a function handle. The factory value of the setting is set to the output of the specified function.

The function handle must point to a function on the MATLAB path. Anonymous or nested function handles are not supported.

You can specify either a factory value or a factory value function for the setting, but not both.

Hidden state, specified as true or false.

When set to true, the factory setting does not display, although it remains accessible.

Read-only state, specified as true or false. When true, the personal or temporary value of the setting cannot be specified.

Function to validate setting, specified as a function handle. When specified, the function is used to validate the value of the factory setting.

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.

Introduced in R2019b