ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
istype.m File Reference

Go to the source code of this file.

Functions

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 specified maximum size varsize. Otherwise, return false. More...
 

Function Documentation

◆ istype()

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 specified maximum size varsize. Otherwise, return false.

Beware that this algorithm converts input values of type char to string before further processing and type checking, that is, the types char to string are assumed to be conformable and compatible with each other, like most other sane languages.

Parameters
[in]varval: The input value to be converted to namelist-compatible value.
[in]vartype: The input scalar MATLAB string containing the expected type of the value given by the input varval.
The following type-conformance rules apply:
  1. if vartype is "string", then varval can be either a MATLAB string or char.
    An input value of type char is always converted to string before further processing.
  2. if vartype is "integer", then varval can be either a MATLAB int8, int16, int32, int64, or a whole-number real value.
  3. if vartype is "logical", then varval can be either a MATLAB int8, int16, int32, int64, a MATLAB real, or a MATLAB logical value.
  4. if vartype is "complex", then varval can be either a MATLAB int8, int16, int32, int64, a MATLAB real, or a MATLAB complex value.
  5. if vartype is "real", then varval can be either a MATLAB int8, int16, int32, int64, or a MATLAB real value (e.g., float, single, double).
    For all other object types, the type-conformance is verified by passing the input varval and vartype directly to the MATLAB intrinsic function isa().
[in]varsize: The input scalar MATLAB integer representing the maximum allowed size of the input value varval.
(optional. If missing, the maximum length of the input varval will not be checked.)
Returns
itis : The output scalar MATLAB logical that is true if and only if the input varval conforms with the specified input type vartype and the specified maximum size varsize, otherwise, it is false.


Possible calling interfaces

itis = pm.introspection.istype(varval, vartype)
itis = pm.introspection.istype(varval, vartype, varsize)


Example usage

1cd(fileparts(mfilename('fullpath'))); % Change working directory to source code directory.
2addpath('../../../'); % Add the ParaMonte library root directory to the search path.
3
4disp('pm.introspection.istype(10000, "integer", 1)')
5disp( pm.introspection.istype(10000, "integer", 1) )
6
7disp('pm.introspection.istype([1, 0], "double", 2)')
8disp( pm.introspection.istype([1, 0], "double", 2) )
9
10disp('pm.introspection.istype(false, "logical", 1)')
11disp( pm.introspection.istype(false, "logical", 1) )
12
13disp('pm.introspection.istype("This is the description", "string", 1)')
14disp( pm.introspection.istype("This is the description", "string", 1) )
15
16disp('pm.introspection.istype("value", "cell", 1)')
17disp( pm.introspection.istype("value", "cell", 1) )
18
19disp('pm.introspection.istype([1, 2], "complex", 1)')
20disp( pm.introspection.istype([1, 2], "complex", 1) )
21
22disp('pm.introspection.istype(1 + 2i, "complex", 1)')
23disp( pm.introspection.istype(1 + 2i, "complex", 1) )
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...
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.

Example output
1pm.introspection.istype(10000, "integer", 1)
2 1
3pm.introspection.istype([1, 0], "double", 2)
4 1
5pm.introspection.istype(false, "logical", 1)
6 1
7pm.introspection.istype("This is the description", "string", 1)
8 1
9pm.introspection.istype("value", "cell", 1)
10 0
11pm.introspection.istype([1, 2], "complex", 1)
12 0
13pm.introspection.istype(1 + 2i, "complex", 1)
14 1


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Joshua Alexander Osborne, May 21 2024, 5:47 PM, University of Texas at Arlington
Fatemeh Bagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.
Amir Shahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin