2%> Return ``
true``
if and only
if the input ``varval`` conforms with the
3%> specified input type ``vartype``, otherwise,
return ``
false``.<br>
6%> If the input argument ``varval`` is a collection of values and the input ``vartype``
7%> is one of the five basic types (``
string``, ``integer``, ``logical``, ``complex``, ``real``),
8%> then each element of the ``varval`` sequence will be tested against the input ``vartype``.<br>
10%> **Beware** that
this algorithm converts input values of type ``
char`` to ``
string``
11%> before further processing and type checking, that is, the types ``
char`` to ``
string``
12%> are assumed to be conformable and compatible with each other, like most other sane languages.<br>
14%> \param[in] varval : The input value whose type must be
verified.
15%> \param[in] vartype : The input scalar MATLAB
string containing the
16%> expected type of the value given by the input ``varval``.<br>
17%> The following type-conformance rules apply:<br>
19%> <li>
if ``vartype`` is ``
"string"``, then ``varval`` can be
20%> either a MATLAB ``
string`` or ``
char``.<br>
21%> An input value of type ``
char`` is always
22%> converted to ``
string`` before further processing.<br>
23%> <li>
if ``vartype`` is ``
"integer"``, then ``varval`` can be
24%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
25%> or a whole-number ``real`` value.<br>
26%> <li>
if ``vartype`` is ``
"logical"``, then ``varval`` can be
27%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
28%> a MATLAB ``real``, or a MATLAB ``logical`` value.<br>
29%> <li>
if ``vartype`` is ``
"complex"``, then ``varval`` can be
30%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
31%> a MATLAB ``real``, or a MATLAB ``complex`` value.<br>
32%> <li>
if ``vartype`` is ``
"real"``, then ``varval`` can be
33%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
34%> or a MATLAB ``real`` value (e.g., ``
float``, ``single``, ``
double``).<br>
35%> For all other
object types, the type-conformance is
verified by
36%> passing the input ``varval`` and ``vartype`` directly to the
37%> MATLAB intrinsic function ``isa()``.<br>
41%> ``itis`` : The output scalar MATLAB logical that is ``
true``
if and only
if
42%> the input ``varval`` conforms with the specified input type ``vartype``,
43%> otherwise, it is ``
false``.<br>
48%> itis = pm.introspection.istype(varval, vartype)
53%> [pm.introspection.verify](@ref
verify)<br>
54%> [pm.introspection.verified](@ref
verified)<br>
55%> [pm.introspection.islenleq](@ref
islenleq)<br>
56%> [pm.introspection.istype](@ref
istype)<br>
59%> \include{lineno} example/introspection/
istype/main.m
61%> \include{lineno} example/introspection/
istype/main.out.m
66%> \JoshuaOsborne, May 21 2024, 5:47 PM, University of Texas at Arlington<br>
67%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
68%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
69function itis =
istype(varval, vartype)
71 varval = string(varval);
73 varvalen = numel(varval);
76 if isa(varval(i),
"cell")
81 if strcmpi(vartype,
"string") || strcmpi(vartype,
"char")
82 itis = isa(value, "
string") || isa(value, "
char");
83 elseif strcmpi(vartype, "integer")
84 itis = isa(value, "int8") || isa(value, "int16") || isa(value, "int32") || isa(value, "int64");
85 if ~itis && isreal(value)
86 itis = rem(value, 1) == 0;
88 elseif strcmpi(vartype, "logical")
89 itis = isa(value, "logical") || isreal(value) || isa(value, "int8") || isa(value, "int16") || isa(value, "int32") || isa(value, "int64");
90 elseif strcmpi(vartype, "complex")
92 elseif strcmpi(vartype, "real") || strcmpi(vartype, "
float") || strcmpi(vartype, "single") || strcmpi(vartype, "
double")
93 itis = isreal(value) || isa(value, "int8") || isa(value, "int16") || isa(value, "int32") || isa(value, "int64");
95 itis = isa(value, vartype);
function verify(in varval, in vartype, in maxlen, in varname)
Verify the type and number of elements of the input varval match the specified input vartype and maxl...
function islenleq(in varval, in maxlen)
Return true if and only if the input varval has the specified maximum size maxlen,...
function isnumeric(in str)
Return a scalar MATLAB logical that is true if and only if the input string can be converted to a sca...
function istype(in varval, in vartype)
Return true if and only if the input varval conforms with the specified input type vartype,...
function verified(in varval, in vartype, in maxlen)
Return true if and only if the input varval conforms with the specified input type vartype and maximu...