Legal names follow the pattern [A-Za-z] [A-Za-z0-9 _] *, that is, an alphabetic character followed by zero or more alphanumeric characters or underscores, before the NAMELENGTHMAX characters.
Since the rules for naming variables and MATLAB functions are the same, you can find genvarname . It sanitizes arbitrary strings into legal MATLAB names.
source share