Library Function li_ckvar

function [sErrMsg, xVarAdjusted] = li_ckvar(xVar, sReqType, varargin)

Checks <xVar> to heed the type definition passed in <sReqType>. If the check was passed, output <sErrMsg> will be an empty string, otherwise it will contain an appropriate error message containing a %s placeholder for the name or a respectively passed description of the argument tested. A second output argument might be assigned that will contain an empty matrix ([]) if the test failed, and the tested argument - optionally adjusted - if the test was passed. Additional arguments might be passed as name-value pairs. Many of these additional arguments are specific to one or more <sReqType> arguments. If passed with an inappropriate <sReqType>, a name-value pair will be ignored. If passed multiple times, the value passed with the first occurence will be used. An option common to all types is '--var-name' that defines the name or description of the variable to be used in error messages.

<sReqType> values and associated options


The tested variable is expected to be interpretable as a boolean (true or false) value. By default strings or row vectors of char equalling case insensitive 'true', 'yes' or 'on' are considered true and respectively 'false', 'no' or 'off' are considered false, any other values of these types return an error message. Integer types are valid only if eqalling 0 for false or 1 for true, barring options. Floating point types are valid only if differing from 0 no more than 10*eps for false and respectively 10*psi from 1 for true, barring options. All numeric types are never valid, if they contain any element with imaginary part unequal to zero. Matlabs logical type is always accepted as is. By default any input dimension is accepted with the exception of char that is only allowed to be a row vector and thus can only represent a scalar boolean value. If a second return value is present, it will be a respective logical scalar or array if the check was successful, and empty othwerwise.

'file-read', 'file-write', 'file-append', 'dir-read' or 'dir-write'

The tested value is expected to represent one or more file objects. By default a scalar string or a row vector of char forming the path of a single file object is is required. The required type values starting on 'file-' expect representations of a regular files, those starting on 'dir-' such of directories. The required type values ending on '-read' expect representations of file objects that exist and are readable by the current user, where in case of directories reading means the listing of its contents in general. The required type values ending on '-write' or '-append' expect file objects, that can be written into with the current users previliges. If the creation of any directories would be required to do so, this is only allowed along with the option --create-all. Type values 'file-write' and 'file-append' are the same appart from handles going in or out of the check. For an incoming handle it would be expected to have been opened for writing or appending respectively, for --return-type 'handle' a respective handle would be opened using the required mode, where necessary. Incoming machine format is always ignored, outgoing always the default, if opened by this utility.


The tested value is expected to represent one or more simulink modelling objects. By default this can be an array of any size consisting of either valid simulink object handles or actual simulink objects, as well as char or string representations of simulink block paths pointing to existing simulink items, inluding cell arrays of char. Any reference to a deleted object is not allowed. Cell arrays might only contain row vectors of char, any mixing up with matlabs string type or any other representatioj is currently not allowed. If a second return value is present, it will be a respective scalar or array of numeric handles, if the check was successful, and empty othwerwise. Simulink modelling objects are only such objects, that directly make up a simulink model, like blocks, line, annotations. Other types representing e.g. parameters, parameter classes or auxiliary objects, like Simulink.IntEnumType or Simulink.BlockPath are generally not accepted.


This type value is generally the same as 'text-line', only that it does not restrict the tested variable to represent a kind of line, here any number and size of dimensions is allowed. Also all options from 'text-line' are shared, with one option added.


The tested variable is expected to be of a type and shape that makes it interpretable as a line of text. By default allowed are row vectors of char or uint8 or int8 and scalars of string or java.lang.String or java.lang.StringBuilder or System.String. The integer types must contain all numbers out of the range of printable 7-Bit ASCII plus CR, LF, TAB. All row vector types might be empty, barring options. All other types might not be empty, but might contain an empty string, barring options. Some types might be excluded by options. All values received in <xVar> or returned in <xVarAdjusted> might still contain newline characters and under that aspect represent more than one single line. There is no check for newline characters.