Skip to Main Content Skip to Search
Product Documentation

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

genvarname | is* | isglobal | iskeyword | namelengthmax

  


Free MATLAB Interactive Kit

Explore how to use MATLAB to make advancements in engineering and science.


Download free kit

Trials Available

Try the latest version of MATLAB and other MathWorks products.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS