In MATLAB, what ASCII characters are allowed in a function name?

I have a set of objects from which I read information containing information that becomes a MATLAB m file. One piece of information ends with the function name in MATLAB. I need to remove all invalid characters from this line before writing the M file to the file system. Can someone tell me which characters make up the set of allowed characters in the function name for MATLAB?

+4
source share
3 answers

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.

+10
source

The short answer is ...

Any alphanumeric or underscore characters if the name begins with a letter.

Longer answer ...

The MATLAB documentation has a section called “Working with Files” that discusses names with more detailed information, in particular, it points to the NAMELENGTHMAX functions (the maximum number of characters in a name that the OS will pay attention to), ISVARNAME (to check the name is correct variable / function) and ISKEYWORD (to display private keywords).

+5
source
+3
source

All Articles