Documentation Center

  • Trial Software
  • Product Updates

isvarname

Determine whether input is valid variable name

Syntax

tf = isvarname('str')
isvarname str

Description

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.

Examples

This variable name is valid:

isvarname foo
ans = 
   1

This one is not because it starts with a number:

isvarname 8th_column
ans =
   0

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

d = date;

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

See Also

| | | | |

Was this topic helpful?