Construct valid MATLAB identifiers from input strings
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.
To ensure that input values are valid and unique, use
matlab.lang.makeUniqueStrings after
matlab.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
strrep or regexprep to convert to
valid characters. For example, convert '@' characters in
S to 'At' using
strrep(S,'@','At'). Then, use
matlab.lang.makeValidName to ensure that all characters
in S are valid.
iskeyword | isletter | isvarname | matlab.lang.makeUniqueStrings | namelengthmax | regexp | regexprep | strrep | who