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``.
6%> \param[in] varval : The input value to be converted to namelist-compatible value.
7%> \param[in] vartype : The input scalar MATLAB
string containing the
8%> expected type of the value given by the input ``varval``.<br>
9%> The following type-conformance rules apply:<br>
11%> <li>
if ``vartype`` is ``
"string"``, then ``varval`` can be
12%> either a MATLAB ``
string`` or ``
char``.<br>
13%> <li>
if ``vartype`` is ``
"integer"``, then ``varval`` can be
14%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
15%> or a whole-number ``real`` value.<br>
16%> <li>
if ``vartype`` is ``
"logical"``, then ``varval`` can be
17%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
18%> a MATLAB ``real``, or a MATLAB ``logical`` value.<br>
19%> <li>
if ``vartype`` is ``
"complex"``, then ``varval`` can be
20%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
21%> a MATLAB ``real``, or a MATLAB ``complex`` value.<br>
22%> <li>
if ``vartype`` is ``
"real"``, then ``varval`` can be
23%> either a MATLAB ``int8``, ``int16``, ``int32``, ``int64``,
24%> or a MATLAB ``real`` value (e.g., ``
float``, ``single``, ``
double``).<br>
25%> For all other
object types, the type-conformance is verified by
26%> passing the input ``varval`` and ``vartype`` directly to the
27%> MATLAB intrinsic function ``isa()``.<br>
29%> \param[in] varsize : The input scalar MATLAB integer representing the
30%> maximum allowed size of the input value ``varval``.<br>
31%> (**optional**. If missing, the maximum length of the
32%> input ``varval`` will not be checked.)
35%> ``itis`` : The output scalar MATLAB logical that is ``
true``
if and only
if
36%> the input ``varval`` conforms with the specified input type ``vartype``
37%> and the specified maximum size ``varsize``, otherwise, it is ``
false``.<br>
42%> itis = pm.introspection.istype(varval, vartype)
43%> itis = pm.introspection.istype(varval, vartype, varsize)
48%> \include{lineno} example/introspection/
istype/main.m
50%> \include{lineno} example/introspection/
istype/main.out.m
55%> \JoshuaOsborne, May 21 2024, 5:47 PM, University of Texas at Arlington<br>
56%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
57%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute
for Computational Engineering and Sciences (ICES), UT Austin<br>
58function itis =
istype(varval, vartype, varsize)
59 varvalen = numel(varval);
62 itis = varvalen <= varsize;
68 if isa(varval(i),
"cell")
73 if strcmpi(vartype,
"string")
74 itis = isa(value, "
string") || isa(value, "
char");
75 elseif strcmpi(vartype, "integer")
76 itis = isa(value, "int8") || isa(value, "int16") || isa(value, "int32") || isa(value, "int64");
77 if ~itis && isreal(value)
78 itis = rem(value, 1) == 0;
80 elseif strcmpi(vartype, "logical")
81 itis = isa(value, "logical") || isreal(value) || isa(value, "int8") || isa(value, "int16") || isa(value, "int32") || isa(value, "int64");
82 elseif strcmpi(vartype, "complex")
84 elseif strcmpi(vartype, "real") || strcmpi(vartype, "
float") || strcmpi(vartype, "single") || strcmpi(vartype, "
double")
85 itis = isreal(value) || isa(value, "int8") || isa(value, "int16") || isa(value, "int32") || isa(value, "int64");
87 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...