2%> Return ``
true``
if and only
if the input ``varval`` conforms with the
3%> specified input type ``vartype`` and the specified maximum size ``varsize``.
4%> Otherwise,
return ``
false``.
7%> Beware that
this algorithm converts input values of type ``
char`` to ``
string``
8%> before further processing and type checking, that is, the types ``
char`` to ``
string``
9%> are assumed to be conformable and compatible with each other, like most other sane languages.<br>
11%> \param[in] varval : The input value to be converted to namelist-compatible value.
12%> \param[in] vartype : The input scalar MATLAB
string containing the
13%> expected type of the value given by the input ``varval``.<br>
14%> The following type-conformance rules apply:<br>
16%> <li>
if ``vartype`` is ``
"string"``, then ``varval`` can be
17%> either a MATLAB ``
string`` or ``
char``.<br>
18%> An input value of type ``
char`` is always
19%> converted to ``
string`` before further processing.<br>
20%> <li>
if ``vartype`` is ``
"integer"``, then ``varval`` can be
21%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
22%> or a whole-number ``real`` value.<br>
23%> <li>
if ``vartype`` is ``
"logical"``, then ``varval`` can be
24%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
25%> a MATLAB ``real``, or a MATLAB ``logical`` value.<br>
26%> <li>
if ``vartype`` is ``
"complex"``, then ``varval`` can be
27%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
28%> a MATLAB ``real``, or a MATLAB ``complex`` value.<br>
29%> <li>
if ``vartype`` is ``
"real"``, then ``varval`` can be
30%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
31%> or a MATLAB ``real`` value (e.g., ``
float``, ``single``, ``
double``).<br>
32%> For all other
object types, the type-conformance is verified by
33%> passing the input ``varval`` and ``vartype`` directly to the
34%> MATLAB intrinsic function ``isa()``.<br>
36%> \param[in] varsize : The input scalar MATLAB integer representing the
37%> maximum allowed size of the input value ``varval``.<br>
38%> (**optional**. If missing, the maximum length of the
39%> input ``varval`` will not be checked.)
42%> ``itis`` : The output scalar MATLAB logical that is ``
true``
if and only
if
43%> the input ``varval`` conforms with the specified input type ``vartype``
44%> and the specified maximum size ``varsize``, otherwise, it is ``
false``.<br>
49%> itis = pm.introspection.istype(varval, vartype)
50%> itis = pm.introspection.istype(varval, vartype, varsize)
55%> \include{lineno} example/introspection/
istype/main.m
57%> \include{lineno} example/introspection/
istype/main.out.m
62%> \JoshuaOsborne, May 21 2024, 5:47 PM, University of Texas at Arlington<br>
63%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
64%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
65function itis =
istype(varval, vartype, varsize)
67 varval = string(varval);
69 varvalen = numel(varval);
72 itis = varvalen <= varsize;
78 if isa(varval(i),
"cell")
83 if strcmpi(vartype,
"string") || strcmpi(vartype,
"char")
84 itis = isa(value, "
string") || isa(value, "
char");
85 elseif strcmpi(vartype, "integer")
86 itis = isa(value, "int8") || isa(value, "int16") || isa(value, "int32") || isa(value, "int64");
87 if ~itis && isreal(value)
88 itis = rem(value, 1) == 0;
90 elseif strcmpi(vartype, "logical")
91 itis = isa(value, "logical") || isreal(value) || isa(value, "int8") || isa(value, "int16") || isa(value, "int32") || isa(value, "int64");
92 elseif strcmpi(vartype, "complex")
94 elseif strcmpi(vartype, "real") || strcmpi(vartype, "
float") || strcmpi(vartype, "single") || strcmpi(vartype, "
double")
95 itis = isreal(value) || isa(value, "int8") || isa(value, "int16") || isa(value, "int32") || isa(value, "int64");
97 itis = isa(value, vartype);
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, in varsize)
Return true if and only if the input varval conforms with the specified input type vartype and the sp...