isvarname - Determine if input is valid variable name - MATLAB (original) (raw)
Main Content
Determine if input is valid variable name
Syntax
Description
tf = isvarname([s](#f72-1047442-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 no 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](#f72-1047442-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.
Examples
Show that input that starts with a number is not a valid variable name.
s = '8th_column'; isvarname(s)
Change the input to a valid variable name.
s = 'column_8'; isvarname(s)
Use the command form to determine if the input is a valid variable name.
Input Arguments
Potential variable name, specified as a character vector, or string.
Example: 'myVar'
Example: "myVar2"
Extended Capabilities
Version History
Introduced before R2006a
The maximum allowed identifier length is increased to 2048. This change allows variables, functions, classes, and many other entities to have names of up to 2048 characters. Longer identifiers negatively impact performance and memory.