addGroup
说明
s = addGroup(
将新设置组添加到指定的父设置组,并返回包含新设置组的 parentgroup
,name
)SettingsGroup
对象。默认情况下,设置组不会隐藏,这意味着它们会显示在父设置组中。
s = addGroup(___,
使用一个或多个名称-值对组参数指定设置组属性。例如,Name,Value
)'Hidden',true
添加一个隐藏设置组。请在所有其他输入参数之后指定名称-值对组。
示例
添加和删除设置组
使用 settings
函数访问设置树的根,然后创建 mysettings
设置组。
s = settings;
newGroup = addGroup(s,"mysettings");
s
s = SettingsGroup with properties: mysettings: [1×1 SettingsGroup] mytest: [1×1 SettingsGroup] matlab: [1×1 SettingsGroup]
使用 removeGroup
删除 mysettings
。
removeGroup(s,"mysettings");
s
s = SettingsGroup with properties: mytest: [1×1 SettingsGroup] matlab: [1×1 SettingsGroup]
添加隐藏的设置组
使用 settings
函数访问设置树的根,然后创建 myhiddensettings
隐藏设置组。由于新组是隐藏的,当显示父设置组时,新组不会显示。
s = settings;
addGroup(s,"myhiddensettings",Hidden=true);
s
s = SettingsGroup with properties: mytest: [1×1 SettingsGroup] matlab: [1×1 SettingsGroup]
尽管 myhiddensettings
不会在设置树中显示,但它是可以访问的。例如,您可以在 myhiddensettings
内创建设置组 myveryhiddensettings
。
addGroup(s.myhiddensettings,"myveryhiddensettings");
s.myhiddensettings
ans = SettingsGroup 'myhiddensettings' with properties: myveryhiddensettings: [1×1 SettingsGroup]
您可以像删除可见组一样删除隐藏组。
removeGroup(s,"myhiddensettings")
验证组中的设置值
创建一个设置组,并为该组指定一个默认验证函数。此函数验证该组中未定义其自己的验证函数的所有设置的值。
创建一个当输入为非数值时会引发错误的验证函数 numericValidationFcn
。
function numericValidationFcn(x) errorMsg = "Value must be numeric."; assert(isnumeric(x),errorMsg); end
使用 settings
函数访问设置树的根,然后创建 myNumericSettings
设置组。指定验证函数。
s = settings; newNumericGroup = addGroup(s,"myNumericSettings",... ValidationFcn=@numericValidationFcn);
如果您在 myNumericSettings
组中创建一个新设置,并尝试将该设置的值设置为非数值,则 MATLAB 将引发错误。例如,如果您运行此语句,它尝试将 PersonalValue
设置为字符串而不是数值,则 MATLAB 将引发错误。
addSetting(newNumericGroup,"mySetting",PersonalValue="Hello")
使用 removeGroup
删除 myNumericSettings
。
removeGroup(s,"myNumericSettings");
输入参数
parentgroup
— 父设置组
SettingsGroup
对象
要向其添加组的父设置组,指定为 SettingsGroup
对象。使用 settings
函数访问根设置组对象和所有可用设置组。
name
— 要添加的设置组的名称
字符向量 | 字符串标量
要添加的设置组的名称,指定为字符向量或字符串标量。如果 name
已存在于指定的父设置组中,MATLAB® 将引发错误。如果 name
匹配 SettingsGroup
对象的方法的名称,如 addSetting
或 hasGroup
,则 MATLAB 也会引发错误。
名称-值参数
将可选的参数对组指定为 Name1=Value1,...,NameN=ValueN
,其中 Name
是参数名称,Value
是对应的值。名称-值参数必须出现在其他参数之后,但参数对组的顺序无关紧要。
在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name
引起来。
示例: addGroup(parentgroup,'myGroup','Hidden',true)
会在指定的父设置组中添加一个新的隐藏设置组。
Hidden
— 隐藏状态
false
(默认) | true
隐藏状态,指定为 true
或 false
。
当设置为 true
时,虽然设置组和组内设置仍可访问,但它们并不显示出来。
ValidationFcn
— 用于验证组内设置的函数
函数句柄
用于验证组内设置的函数,指定为函数句柄。如果指定了该函数,它将用于验证组中未定义其自己的验证函数的所有设置的值。
函数句柄必须与接受潜在设置值作为输入参数、没有输出参数并且在验证失败时引发错误的函数相关联。
函数句柄必须指向 MATLAB 路径上的函数。不支持匿名或嵌套的函数句柄。
版本历史记录
在 R2019b 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)