- The toolbox to which the function belongs is not installed.
- The search path to the function has been changed.
- The function is part of a toolbox that you do not have a license for.
Follow the steps described in this section to resolve this situation.
Verify the Spelling of the Function Name
One of the most common errors is misspelling the function name. Especially with longer
function names or names containing similar characters (e.g., letter l and numeral one), it
is easy to make an error that is not easily detected.
If you misspell a MATLAB function, a suggested function name appears in the Command
Window. For example, this command fails because it includes an uppercase letter in the
function name:
accumArray
Undefined function or variable 'accumArray'.
Did you mean:
>> accumarray
Press Enter to execute the suggested command or Esc to dismiss it.
Make Sure the Function Name Matches the File Name
You establish the name for a function when you write its function definition line. This
name should always match the name of the file you save it to. For example, if you create a
function named curveplot,
function curveplot(xVal, yVal)
- program code -
then you should name the file containing that function curveplot.m. If you create a
pcode file for the function, then name that file curveplot.p. In the case of conflicting
function and file names, the file name overrides the name given to the function. In this
example, if you save the curveplot function to a file named curveplotfunction.m,
then attempts to invoke the function using the function name will fail:
curveplot
Undefined function or variable 'curveplot'.
1 Syntax Basics