MATLAB 帮助中心
本页翻译不是最新的。点击此处可查看最新英文版本。
确定字典是否包含键
自 R2022b 起
tf = isKey(d,key)
如果配置的字典包含指定的键,则 tf = isKey(d,key) 返回逻辑值 1 (true),否则返回逻辑值 0 (false)。如果 d 是未配置的字典,isKey 将引发错误。
d
key
1
true
0
false
isKey
如果 key 是指定多个键的数组,则 tf 是具有相同大小的逻辑数组。
tf
示例
全部折叠
创建一个包含几个键-值对组的字典。
names = ["Unicycle" "Bicycle" "Tricycle"]; wheels = [1 2 3]; d = dictionary(wheels,names)
d = dictionary (double ⟼ string) with 3 entries: 1 ⟼ "Unicycle" 2 ⟼ "Bicycle" 3 ⟼ "Tricycle"
确定字典中是否有 1 作为键。
tf = isKey(d,1)
tf = logical 1
搜索多个键。
key = [1 2 3 4 5]; tf = isKey(d,key)
tf = 1×5 logical array 1 1 1 0 0
dictionary
字典,指定为 dictionary 对象。如果 d 未配置,isKey 将引发错误。
键集,指定为数组。key 的数据类型必须匹配或可转换为 d 中键的数据类型。
全部展开
用法说明和限制:
即使字典在代码生成时为常量,代码生成器也不会将该字典视为常量。这意味着 isKey 函数不返回常量。不能将 isKey 函数的输出传递给需要常量输入的函数。不能将 isKey 函数的输出用于需要常量的操作,如对异构元胞数组进行索引。代码生成器也无法对 isKey 函数的输出执行依赖常量的优化,如常量折叠。
有关为 MATLAB® 字典生成 C/C++ 代码时适用的其他注意事项,请参阅代码生成的字典限制 (MATLAB Coder)。
您可以为字典 isKey 函数生成 C/C++ 代码。
dictionary | configureDictionary | insert | lookup | remove | entries | keys | values | types | numEntries | isConfigured
configureDictionary
insert
lookup
remove
entries
keys
values
types
numEntries
isConfigured
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
欧洲
亚太
联系您当地的办事处