matched = validatestring(str, validStrings)
matched = validatestring(str, validStrings, argIndex)
matched = validatestring(str, validStrings, funcName)
matched = validatestring(str, validStrings, funcName, varName)
matched = validatestring(str, validStrings, funcName, varName, argIndex)
| Parameter | Description |
|---|---|
| str | text to validate, specified as a character vector or string scalar. |
| validStrings | allowed text values, specified as a character vector, string array, or cell array of character vectors. |
| argIndex | positive integer used in generated error messages to identify the argument position. |
| funcName | function name used in generated error identifiers. |
| varName | variable name used in generated error messages. |
| Parameter | Description |
|---|---|
| matched | matched value from validStrings. The output is a string scalar when validStrings is a string array; otherwise it is a character vector. |
validatestring accepts exact matches and leading partial matches without case sensitivity. Exact matches are preferred over partial matches.
If one leading partial match exists, that value is returned. If several leading partial matches exist and every matching value forms a substring chain, the shortest matching value is returned. If several leading partial matches exist and they do not form such a chain, an ambiguity error is raised.
Error messages can include an argument position, a variable name, and a function name depending on the syntax used.
shape = validatestring('Rect', {'square', 'rectangle', 'triangle'});
direction = validatestring("LEFT", ["left", "right"])
value = validatestring('rig', {'righteously', 'right', 'righteous'})
units = {'cm', 'm', 'in', 'ft'};
choice = validatestring('CM', units, 'findArea', 'units', 4)
| Version | Description |
|---|---|
| 1.0.0 | initial version |