isa
Return true if a variable has the requested class or type.
📝Syntax
res = isa(var, className)
📥Input Arguments
Parameter Description
var a variable
className a class or type name as a string
📤Output Arguments
Parameter Description
res a logical: true or false
📄Description

isa returns logical 1 when var is an instance of className, and logical 0 otherwise.

className can be a Nelson type name such as double, cell, numeric, float, or integer.

For classdef objects, isa accepts the class name and supported superclass names, including handle for handle classes.

For sparse arrays, isa tests the stored value class, such as double or logical. Use issparse to test sparse storage.

💡Examples
Test a numeric type.
A = 3;
res = isa(A, 'double')
Test the stored value class of a sparse array.
S = sparse([2 0 3]);
isDouble = isa(S, 'double')
isSparse = issparse(S)
Test a classdef handle object.
clear classes
d = [tempdir(), 'nelson_help_isa/'];
mkdir(d);
filewrite([d, '/NelsonHelpIsaCounter.m'], ["classdef NelsonHelpIsaCounter < handle"; "  properties"; "    Count = 0"; "  end"; "end"]);
addpath(d);
obj = NelsonHelpIsaCounter();
isCounter = isa(obj, 'NelsonHelpIsaCounter')
isHandle = isa(obj, 'handle')
delete(obj)
🔗See Also
classissparseisobjectclassdef
🕔Version History
Version Description
1.0.0 initial version
2.0.0 classdef object support documented
2.0.0 sparse arrays are tested by stored value class
Edit this page on GitHub