Type of underlying data determining array behavior
typename = underlyingType( returns the name
of the underlying MATLAB® data type that determines how the array
typename is returned as a character vector.
class function is useful to determine the class of a variable.
For most classes,
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
Query Underlying Data Type
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'
ans = 'single'
x is a fundamental data type such as
underlyingType(x) return the
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'
ans = 'table'
x is a container data type such as
cell, the commands
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'
ans = 'double'
x belongs to a class that can have underlying data that
changes how the variable behaves, such as
distributed, the commands
underlyingType(x) return different
answers. In this case,
class(x) returns the name of the class for the
underlyingType(x) returns the name of the data type
for the underlying data.
X — Input array or object
variable | expression
Input array or object, specified as a variable or expression.
'double' since the
gpuArray contains underlying
data of type
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).