Construct validMATLABidentifiers from input strings
N = matlab.lang.makeValidName(S)
N = matlab.lang.makeValidName(S,Name,Value)
[N, modified] = matlab.lang.makeValidName(___)
constructs valid MATLAB®identifiers,N
= matlab.lang.makeValidName(S
)N
, from input strings,S
. ThemakeValidName
function does not guarantee the strings inN
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 tonamelengthmax
.
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 moreN
= matlab.lang.makeValidName(S
,Name,Value
)Name,Value
pair arguments.
To ensure that input values are valid and unique, usematlab.lang.makeUniqueStrings
aftermatlab.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 asstrrep
orregexprep
to convert to valid characters. For example, convert'@'
characters inS
to'At'
usingstrrep(S,'@','At')
. Then, usematlab.lang.makeValidName
to ensure that all characters inS
are valid.
iskeyword
|isletter
|isvarname
|matlab.lang.makeUniqueStrings
|namelengthmax
|regexp
|regexprep
|strrep
|who