isprotected
确定分类数组的类别是否受保护
说明
示例
确定类别是否受保护
创建一个大小包含 10 个对象的分类数组。对值 'S'
、'M'
和 'L'
应用名称 small
、medium
和 large
。
valueset = {'S','M','L'}; catnames = {'small','medium','large'}; A = categorical({'M';'L';'S';'S';'M';'L';'M';'L';'M';'S'},... valueset,catnames,'Ordinal',true)
A = 10x1 categorical
medium
large
small
small
medium
large
medium
large
medium
small
A
是一个 10×1 的分类数组。
显示 A
的类别。
categories(A)
ans = 3x1 cell
{'small' }
{'medium'}
{'large' }
确定 A
的类别是否受保护。
tf = isprotected(A)
tf = logical
1
由于 A
是有序分类数组,因此类别受保护。如果试图添加不属于现有类别之一的新值(例如 A(11) = 'xlarge'
),则返回一个错误。
先使用 addcats
为 xlarge
添加新类别。
A = addcats(A,'xlarge','After','large');
虽然 A
受保护,但您现在仍可以为 xlarge
添加值,因为它现在已经有了这个新类别。
A(11) = 'xlarge'
A = 11x1 categorical
medium
large
small
small
medium
large
medium
large
medium
small
xlarge
A
现在是包含四个类别的 11×1 分类数组,满足 small < medium < large < xlarge
。
输入参数
A
— 分类数组
向量 | 矩阵 | 多维数组
分类数组,指定为向量、矩阵或多维数组。
有序分类数组的类别始终受保护。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
此函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
此函数完全支持代码生成。有关详细信息,请参阅Code Generation for Categorical Arrays (MATLAB Coder)。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅Run MATLAB Functions in Thread-Based Environment。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
此函数完全支持分布式数组。有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
版本历史记录
在 R2013b 中推出
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)