genvarname
(To be removed) Construct valid variable name from string
genvarname will be removed in a future release. Use matlab.lang.makeValidName and matlab.lang.makeUniqueStrings instead.
Description
varname = genvarname(
constructs a string or character vector str)varname that is similar
to or the same as the str input, and can be used as a valid
variable name. If str is a string array or cell array of
character vectors, genvarname returns a string array or cell
array of character vectors in varname. The elements returned by
genvarname are guaranteed to be different from each
other.
Note
genvarname does not create a variable in the
MATLAB® workspace. You cannot, therefore, assign a value to the output
of genvarname.
varname = genvarname(
returns a valid variable name that is different from any name listed in the
str,exclusions)exclusions input.
Specify the function who in
exclusions to create a variable name that will be unique in
the current MATLAB workspace.
Examples
Input Arguments
Tips
A valid MATLAB variable name consists of letters, digits, and underscores, such that the first character is a letter, and the length of the name is less than or equal to the value returned by the
namelengthmaxfunction. Any name that exceedsnamelengthmaxis truncated in thevarnameoutput.If the
strinput contains any white-space characters,genvarnameremoves them and capitalizes the next alphabetic character instr. Ifstrcontains any nonalphanumeric characters,genvarnametranslates these characters into their hexadecimal value.
Extended Capabilities
Version History
Introduced before R2006a
See Also
isvarname | iskeyword | isletter | namelengthmax | who | regexp | matlab.lang.makeValidName | matlab.lang.makeUniqueStrings