Documentation

isa

Determine if input is object of specified class

Syntax

tf = isa(obj,ClassName)
tf = isa(obj,classCategory)

Description

tf = isa(obj,ClassName) returns true if obj is an instance of the class specified by ClassName, and false otherwise. isa also returns true if obj is an instance of a class that is derived from ClassName.

obj can be any MATLAB® variable.

ClassName can be any of the following:

  • Name of any MATLAB class or fundamental type

  • Name of a Java®, or .NET class

 MATLAB Fundamental Types

tf = isa(obj,classCategory) returns true if obj is an instance of any of the classes in the specified classCategory, and false otherwise. isa also returns true if obj is an instance of a class that is derived from any of the classes in classCategory.

classCategory can be 'numeric', 'float', or 'integer', representing a category of numeric types:

 Categories of Numeric Types

To test for a sparse array, use issparse. To test for a complex array, use ~isreal.

Examples

These examples show the values returned by isa when passed different types:

Determine if the value returned by the pi function is of class double:

isa(pi,'double')

ans =

     1

More generally, determine if the value returned by the pi function is a numeric value:

isa(pi,'numeric')

ans =

     1

isa also returns true for the float category because the class double is a floating-point type. However, pi does not return an integer type:

isa(pi,'integer')

ans =

     0

Determine if the 2-by-3 array returned by true is of type logical:

isa(true(2,3),'logical')

ans =

     1

Identify an instance of the MATLAB containers.Map class:

colorcodes = containers.Map({'Color','RGB'},...
    {'Yellow',uint8([255,255,0])});
isa(colorcodes,'containers.Map')

ans =

     1

The map key, RGB, references a uint8 array:

isa(colorcodes('RGB'),'integer')

ans =

     1

Specifying a particular integer class provides more specific testing:

if strcmp(colorcodes('Color'),'Yellow') && ...
        isa(colorcodes('RGB'),'uint8')
    disp '''The Color is Yellow and the RGB numbers are uint8 values'''
end
'The Color is Yellow and the RGB numbers are uint8 values'

Introduced before R2006a

Was this topic helpful?