This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Determine if input is valid variable name


tf = isvarname(s)
isvarname s



tf = isvarname(s) determines if input s is a valid variable name. If s is a valid MATLAB® variable name the isvarname function returns logical 1 (true). Otherwise it returns logical 0 (false).

A valid variable name begins with a letter and contains not more than namelengthmax characters. 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 the iskeyword function.

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


collapse all

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

s = '8th_column';
ans = logical

Change the input to a valid variable name.

s = 'column_8';
ans = logical

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

isvarname column_8
ans = logical

Input Arguments

collapse all

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

Example: 'myVar'

Example: "myVar2"

Introduced before R2006a