isUnderlyingType - Determine whether input has specified underlying data type - MATLAB (original) (raw)

Main Content

Determine whether input has specified underlying data type

Since R2020b

Syntax

Description

tf = isUnderlyingType([X](#mw%5F053e58d1-d54c-49ff-a36b-30002a4f64f1),[typename](#mw%5Fb2c3a670-f846-4d45-9852-d7307703cbe3)) returns logical 1 (true) if the underlying data type of X is equal to typename, as returned byunderlyingType(X). Otherwise, the result is logical0 (false).

example

Examples

collapse all

Use isUnderlyingType to query the data type of several variables.

Create a numeric variable that has a data type of single and then test whether the underlying data type is also single.

x = single(5); tf = isUnderlyingType(x,"single")

The result is true because underlyingType(x) returns 'single'.

Next, create a table with two variables and then determine whether the underlying data type is string.

x = table([1; 2; 3],["a"; "b"; "c"]); tf = isUnderlyingType(x,"string")

In this case, the result is false becauseunderlyingType(x) returns 'table'.

Now, create a distributed array (requires Parallel Computing Toolbox™) and then determine whether the underlying data type isdouble.

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

The result is true because underlyingType(x) returns 'double'. In this case, class(x) returns the name of the class for the variable, while underlyingType(x) returns the name of the data type for the underlying data.

Input Arguments

collapse all

Input array or object, specified as a variable or expression.

Example: isUnderlyingType(gpuArray(double(1)),"single") tests whether the input gpuArray contains underlying data of typesingle.

Name of data type to test, specified as a character vector or string scalar.

Example: isUnderlyingType(X,"double") tests whetherX has underlying type double.

Data Types: char | string

Extended Capabilities

expand all

Usage notes and limitations:

The isUnderlyingType function fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray (Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).

Version History

Introduced in R2020b