ISA Test Type of Variable

Section: Inspection Functions

Usage

Tests the type of a variable. The syntax for its use is
   y = isa(x,type)

where x is the variable to test, and type is the type. Supported built-in types are

If the argument is a user-defined type (via the class function), then the name of that class is returned.

Examples

Here are some examples of the isa call.
--> a = {1}
a = 
  <cell array> - size: [1 1]
 [1]    
--> isa(a,'string')
ans = 
  <logical>  - size: [1 1]
 0  
--> isa(a,'cell')
ans = 
  <logical>  - size: [1 1]
 1  

Here we use isa along with shortcut boolean evaluation to safely determine if a variable contains the string 'hello'

--> a = 'hello'
a = 
  <string>  - size: [1 5]
 hello
--> isa(a,'string') && strcmp(a,'hello')
ans = 
  <logical>  - size: [1 1]
 1