Main Content

underlyingType

Type of underlying data determining array behavior

Since R2020b

Description

example

typename = underlyingType(X) returns the name of the underlying MATLAB® data type that determines how the array X behaves. typename is returned as a character vector.

The class function is useful to determine the class of a variable. For most classes, underlyingType(X) and class(X) return the same answer. However, some classes in MATLAB can contain underlying data that has a different type compared to what class returns. Example classes include gpuArray (Parallel Computing Toolbox), dlarray (Deep Learning Toolbox), and distributed (Parallel Computing Toolbox). The behavior of these classes is determined by the type of the underlying data they contain. For example, a distributed array containing double values behaves like a double array.

Examples

collapse all

Use underlyingType and class to test the data types of several variables.

Create a numeric variable that has a data type of single and then query the class and underlying data type.

x = single(5);
class(x)
ans =

    'single'
underlyingType(x)
ans =

    'single'

When x is a fundamental data type such as single, double, or string, both class(x) and underlyingType(x) return the same answer.

Next, create a table with two variables and then query the class and underlying data type.

x = table([1; 2; 3],["a"; "b"; "c"]);
class(x)
ans =

    'table'
underlyingType(x)
ans =

    'table'

When x is a container data type such as table, timetable, or cell, the commands class(x) and underlyingType(x) still return the same answer. This is because container data types do not change their behavior based on the underlying data type.

Now, create a gpuArray (requires Parallel Computing Toolbox™) and then query the class and underlying data type.

x = gpuArray(1:10);
class(x)
ans =

    'gpuArray'
underlyingType(x)
ans =

    'double'

When x belongs to a class that can have underlying data that changes how the variable behaves, such as gpuArray, dlarray, or distributed, the commands class(x) and underlyingType(x) return different answers. 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: underlyingType(gpuArray(double(1))) returns 'double' since the gpuArray contains underlying data of type double.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Version History

Introduced in R2020b