Documentation Center

  • Trial Software
  • Product Updates


Determine whether input is valid variable name


tf = isvarname('str')
isvarname str


tf = isvarname('str') returns logical 1 (true) if the string str is a valid MATLAB® variable name and logical 0 (false) otherwise. A valid variable name is a character string of letters, digits, and underscores, totaling not more than namelengthmax characters and beginning with a letter.

MATLAB keywords are not valid variable names. Type the command iskeyword with no input arguments to see a list of MATLAB keywords.

isvarname str uses the MATLAB command format.


This variable name is valid:

isvarname foo
ans = 

This one is not because it starts with a number:

isvarname 8th_column
ans =

If you are building strings from various pieces, place the construction in parentheses.

d = date;

isvarname(['Monday_', d(1:2)])
ans = 

See Also

| | | | |

Was this topic helpful?