isUnderlyingType
说明
示例
测试基础数据类型
使用 isUnderlyingType
查询多个变量的数据类型。
创建一个数据类型为 single
的数值变量,然后测试基础数据类型是否也是 single
。
x = single(5);
tf = isUnderlyingType(x,"single")
tf = logical 1
结果是 true
,因为 underlyingType(x)
返回 'single'
。
接下来,用两个变量创建一个 table
,然后确定基础数据类型是否为 string
。
x = table([1; 2; 3],["a"; "b"; "c"]); tf = isUnderlyingType(x,"string")
tf = logical 0
在这种情况下,结果是 false
,因为 underlyingType(x)
返回 'table'
。
现在,创建一个 distributed
数组(需要 Parallel Computing Toolbox™),然后确定基础数据类型是否为 double
。
x = distributed(1:10);
tf = isUnderlyingType(x,"double")
Starting parallel pool (parpool) using the 'local' profile ... Connected to the parallel pool (number of workers: 6). tf = logical 1
结果是 true
,因为 underlyingType(x)
返回 'double'
。在这种情况下,class(x)
返回变量所属类的名称,而 underlyingType(x)
返回基础数据的数据类型名称。
输入参数
X
— 输入数组或对象
变量 | 表达式
输入数组或对象,指定为变量或表达式。
示例: isUnderlyingType(gpuArray(double(1)),"single")
测试输入 gpuArray
是否包含 single
类型的基础数据。
typename
— 要测试的数据类型的名称
字符向量 | 字符串标量
要测试的数据类型的名称,指定为字符向量或字符串标量。
示例: isUnderlyingType(X,"double")
测试 X
是否具有基础类型 double
。
数据类型: char
| string
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
用法说明和限制:
不支持
dlarray
(Deep Learning Toolbox) 类型的输入参数X
。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅在基于线程的环境中运行 MATLAB 函数。
GPU 数组
通过使用 Parallel Computing Toolbox™ 在图形处理单元 (GPU) 上运行来加快代码执行。
此函数完全支持 GPU 数组。有关详细信息,请参阅Run MATLAB Functions on a GPU (Parallel Computing Toolbox)。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
此函数完全支持分布式数组。有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
版本历史记录
在 R2020b 中推出
另请参阅
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)