isa
Returns result R if the input, v, belongs to the class, class.
Syntax
R = isa(v, class)
Inputs
- v
- Given input variable.
- class
- Class name to check for. In addition to specific class names, class
can also have the following values:
- 'integer'
- Returns true if v is an integer.
- 'float'
- Returns true if v is a scalar.
- 'double'
- Returns true if v is a scalar.
- 'numeric'
- Returns true if v is an integer or a scalar.
Outputs
- R
- R is true if v belongs to class. If class is of type cell, R will also be of type cell, with the same size as R and each element containing the result of the isa command.
Examples
Logical output example, checking for
subclass:
classdef shape
properties
color
end
methods
function s=shape(color1)
s.color = color1;
end
function disp(s)
fprintf('The shape has color %s\n', s.color);
end
end
end
classdef circle < shape
properties
r
end
methods
function c = circle(radius, color)
c = c@shape(color); % Special construct for instantiating the superclass
c.r = radius;
end
function disp(c)
disp@shape(c); % Call the superclass display first (optional)
fprintf('Radius = %f\n',c.r);
end
end
end
c = circle(3,'blue');
R1 = isa(c, 'circle')
R2 = isa(c, 'shape')
R1 = 1
R2 = 1
Cell output example:
R = isa([1;2;3], {'double', 'float', 'integer', 'numeric', 'foo'})
R =
{
[1,1] 1
[1,2] 1
[1,3] 0
[1,4] 1
[1,5] 0
}