isa

Tests whether a value belongs to a class or to a class category.

Category: Language Fundamentals > Data Types

Syntax

tf = isa(obj, classname)

Returns true if obj is of that class, or inherits from it.

Description

'numeric' covers all integer and floating-point classes, 'float' covers single and double, and 'integer' covers the signed and unsigned integers. Logical and char are not numeric. Unlike strcmp(class(x), ...), isa also respects class hierarchies.

Input arguments

obj
Any value.
classname
Class name such as 'double' or 'struct', or one of the categories 'numeric', 'float', 'integer'. A cell array tests several names.

Output arguments

tf
Logical scalar (or an array when classname is a cell array).

Example

Classes and categories

isa(5, 'numeric')
isa(int8(1), 'integer')
isa(int8(1), 'float')
isa(single(1), 'float')
isa(true, 'numeric')
Output
ans = logical
   1
ans = logical
   1
ans = logical
   0
ans = logical
   1
ans = logical
   0

See also

class isnumeric isfloat isinteger validateattributes