How to Manually Convert Input Arguments
If it is at all possible, avoid manual conversion of input arguments that contain text, and
instead use the convertStringsToChars or convertCharsToStrings functions.
Checking the data types of input arguments and converting them yourself is a tedious
approach, prone to errors.If you must convert input arguments, then use the functions in this table.Conversion Function
String scalar to character vector char
String array to cell array of character
vectorscellstrCharacter vector to string scalar string
Cell array of character vectors to string
arraystringHow to Check Argument Data Types
To check the data type of an input argument that could contain text, consider using the
patterns shown in this table.Required Input Argument
TypeOld Check New CheckCharacter vector or string
scalarischar(X) ischar(X) ||
isStringScalar(X)
validateattributes(X,
{'char','string'},
{'scalartext'})
Character vector or string
scalarvalidateattributes(X,
{'char'},{'row'})validateattributes(X,
{'char','string'},
{'scalartext'})
Nonempty character vector
or string scalarischar(X) &&
~isempty(X)(ischar(X) ||
isStringScalar(X)) &&
strlength(X) ~= 06 Characters and Strings