Main Content

iptcheckstrs

Check validity of parameter name

iptcheckstrs will be removed in a future release. Use validatestring instead.

Description

example

param = iptcheckstrs(str,valid_strs,func_name,var_name,arg_pos) checks whether str is a valid parameter name and issues a formatted error message if the parameter name is invalid.

  • If there is a case-insensitive, unambiguous match between str and a valid parameter name in valid_strs, then iptcheckstrs returns the valid parameter name in param.

  • If there is no match or the match is ambiguous, then iptcheckstrs issues a formatted error message that includes information about the function name (func_name), the variable name (var_name), and the argument position (arg_pos). These values are used only to create the error message, not to check whether the parameter is valid.

The figure shows the format of the error message and indicates which parts you can customize using iptcheckstrs arguments.

Formatted error message that includes a function name, argument position, variable name, and the valid parameter names.

Examples

collapse all

Define a cell array of character vectors that contains valid parameter names. To trigger an error message, pass in a character vector that is not in the cell array.

validSuits = {'spades','hearts','diamonds','clubs'};
selectedSuit = iptcheckstrs('stars',validSuits,"isSuit","selectedSuit",2)
Function ISSUIT expected its second input argument, selectedSuit,
to match one of these:  spades, hearts, diamonds, clubs

The input, 'stars', did not match any of the valid strings.

Define a cell array of character vectors that contains valid parameter names. Check the validity of a parameter name that differs only by case from a character vector in the cell array.

validSuits = {'spades','hearts','diamonds','clubs'};
selectedSuit = iptcheckstrs('Spades',validSuits,"isSuit","selectedSuit",2)
selectedSuit =

    'spades'

Input Arguments

collapse all

Parameter name to check, specified as a character vector.

Valid parameter names, specified as a cell array of character vectors.

Function name to include in an error message when str is not a valid parameter name, specified as a character vector or string scalar.

Data Types: char | string

Variable name to include in an error message when str is not a valid parameter name, specified as a character vector or string scalar.

Data Types: char | string

Argument position to include in an error message when str is not a valid parameter name, specified as a positive integer.

Output Arguments

collapse all

Validated parameter name, returned as a character vector.

Version History

Introduced before R2006a