matlab.lang.makeValidName
Construct valid MATLAB identifiers from input strings
Syntax
Description
constructs valid MATLAB® identifiers, N = matlab.lang.makeValidName(S)N, from input strings,
S. The makeValidName function does not
guarantee the strings in N are unique.
A valid MATLAB identifier is a character vector of alphanumerics (A–Z, a–z, 0–9) and
underscores, such that the first character is a letter and the length of the
character vector is less than or equal to namelengthmax.
makeValidName deletes any whitespace characters before
replacing any characters that are not alphanumerics or underscores. If a whitespace
character is followed by a lowercase letter, makeValidName
converts the letter to the corresponding uppercase character.
includes additional options specified by one or more N = matlab.lang.makeValidName(S,Name,Value)Name,Value
pair arguments.
Examples
Input Arguments
Name-Value Arguments
Output Arguments
Tips
To ensure that input values are valid and unique, use
matlab.lang.makeUniqueStringsaftermatlab.lang.makeValidName.S = {'my.Name','my_Name','my_Name'}; validValues = matlab.lang.makeValidName(S) validUniqueValues = matlab.lang.makeUniqueStrings(validValues,{},... namelengthmax)validValues = 'my_Name' 'my_Name' 'my_Name' validUniqueValues = 'my_Name' 'my_Name_1' 'my_Name_2'To customize an invalid character replacement, first use functions such as
strreporregexprepto convert to valid characters. For example, convert'@'characters inSto'At'usingstrrep(S,'@','At'). Then, usematlab.lang.makeValidNameto ensure that all characters inSare valid.
Version History
Introduced in R2014aSee Also
matlab.lang.makeUniqueStrings | isvarname | iskeyword | isletter | namelengthmax | who | strrep | regexp | regexprep