|Programming and Data Types|
The same guidelines that apply to MATLAB variables at the command line also apply to variables in M-files:
MATLAB variable names must begin with a letter, which may be followed by any combination of letters, digits, and underscores. MATLAB distinguishes between uppercase and lowercase characters, so
a are not the same variable.
Although variable names can be of any length, MATLAB uses only the first
N characters of the name, (where
N is the number returned by the function
namelengthmax), and ignores the rest. Hence, it is important to make each variable name unique in the first
N characters to enable MATLAB to distinguish variables.
Verifying a Variable Name
You can use the
isvarname function to make sure a name is valid before you use it.
isvarname returns 1 if the name is valid, and 0 otherwise.
Avoid Using Function Names for Variables
When naming a variable, make sure you are not using a name that is already used as a function name. If you define a variable with a function name, you won't be able to call that function until you either
clear the variable from memory, or invoke the function using
For example, if you enter the following command, you will not be able to use the MATLAB
disp function until you clear the variable with
To test whether a proposed variable name is already used as a function name, type
|Private Functions||Local Variables|