Main Content

isvarname

Determine if input is valid variable name

Description

example

tf = isvarname(s)determines if inputsis a valid variable name. Ifsis a valid MATLAB®variable name theisvarnamefunction returns logical1(true). Otherwise it returns logical0(false).

A valid variable name begins with a letter and contains not more thannamelengthmaxcharacters. Valid variable names can include letters, digits, and underscores. MATLAB keywords are not valid variable names. To determine if the input is a MATLAB keyword, use theiskeywordfunction.

isvarnamesis the command form of the syntax. The command form requires fewer special characters. You do not need parentheses or single quotes around the input.

Examples

collapse all

Show that input that starts with a number is not a valid variable name.

s ='8th_column'; isvarname(s)
ans =logical0

Change the input to a valid variable name.

s ='column_8'; isvarname(s)
ans =logical1

Use the command form to determine if the input is a valid variable name.

isvarnamecolumn_8
ans =logical1

Input Arguments

collapse all

Potential variable name, specified as a character vector, or string.

Example:'myVar'

Example:"myVar2"

Introduced before R2006a