Common Errors When Calling Functions
In this section...
“Conflicting Function and Variable Names” on page 1-13
“Undefined Functions or Variables” on page 1-13
Conflicting Function and Variable Names
MATLAB throws an error if a variable and function have been given the same name and
there is insufficient information available for MATLAB to resolve the conflict. You may see
an error message something like the following:
Error: <functionName> was previously used as a variable,
conflicting with its use here as the name of a function
or command.
where <functionName> is the name of the function.
Certain uses of the eval and load functions can also result in a similar conflict between
variable and function names. For more information, see:
- “Conflicts with Function Names” on page 1-5
- “Unexpected Results When Loading Variables Within a Function”
- “Alternatives to the eval Function” on page 2-87
Undefined Functions or Variables
You may encounter the following error message, or something similar, while working with
functions or variables in MATLAB:
Undefined function or variable 'x'.
These errors usually indicate that MATLAB cannot find a particular variable or MATLAB
program file in the current directory or on the search path. The root cause is likely to be
one of the following:
- The name of the function has been misspelled.
- The function name and name of the file containing the function are not the same.
Common Errors When Calling Functions