isa - Determine if input is instance of specified class - MATLAB (original) (raw)
Determine if input is instance of specified class
Syntax
Description
tf = isa([A](#mw%5F8bc7b96d-3c65-4642-9614-cb8f9593b20f),[classname](#mw%5F0e9e39f7-a2c6-4979-91fe-87f370e64425))
returns 1
(true
) if A
is an instance of classname
or a subclass of classname
. Otherwise, it returns 0
(false
). The input argumentA
can have any data type.
If A
is an object, then isa
returns1
if dataType
is either the class ofA
or a superclass of A
.
tf = isa([A](#mw%5F8bc7b96d-3c65-4642-9614-cb8f9593b20f),[numericCategory](#mw%5F03d6672c-40ca-4125-86d4-4ef06fab0a39))
returns 1
(true
) if the data type ofA
belongs to the category specified bynumericCategory
. Otherwise, it returns 0
(false
).
If A
is an object, then isa
returns1
if the class of A
, or any superclass ofA
, belongs to the specified category.
Examples
Determine If Variables Have Specified Data Types
Create a numeric variable and determine if its data type is double
.
A = 3.1416; tf = isa(A,'double')
Create an array of 32-bit integers and determine if its data type is int32
.
A = 1x5 int32 row vector
0 2 4 6 8
Determine if the data type of A
is char
.
Determine If Variable Type Belongs to Specified Categories
Create an array whose data type is uint8
. Determine if the array has a data type that belongs to the integer
category.
A = 1x5 uint8 row vector
0 2 4 6 8
Determine if the data type of A
belongs to the float
category.
Input Arguments
A
— Input array
array
classname
— Class name
character vector | string scalar
Class name, specified as a character vector or string scalar.classname
can be the name of:
- Any fundamental data type or MATLAB® class
- A Java® or .NET class
The table shows the names of many commonly used MATLAB data types.
'half' | Half-precision number |
---|---|
'single' | Single-precision number |
'double' | Double-precision number |
'int8' | Signed 8-bit integer |
'int16' | Signed 16-bit integer |
'int32' | Signed 32-bit integer |
'int64' | Signed 64-bit integer |
'uint8' | Unsigned 8-bit integer |
'uint16' | Unsigned 16-bit integer |
'uint32' | Unsigned 32-bit integer |
'uint64' | Unsigned 64-bit integer |
'logical' | Logical 1 (true) or 0 (false) |
'char' | Character |
'string' | String array |
'struct' | Structure array |
'cell' | Cell array |
'table' | Table |
'timetable' | Timetable |
'function_handle' | Function handle |
numericCategory
— Data type category
'numeric'
| 'float'
| 'integer'
Data type category, specified as 'numeric'
,'float'
, or 'integer'
. These values represent categories of numeric types, as shown in the table.
'numeric' | Integer or floating-point array, having one of these data types:doublesinglehalfint8int16int32int64uint8uint16uint32uint64 |
---|---|
'float' | Single- or double-precision floating-point array, having either of these data types:doublesinglehalf |
'integer' | Signed or unsigned integer array, having one of these data types:int8int16int32int64uint8uint16uint32uint64 |
Tips
- To test whether the input array is sparse, use the
issparse
function. - To test whether the input array has any imaginary or complex elements, use
~isreal(A)
.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced before R2006a