Why can't Matlab see my function?

user920761 picture user920761 · Aug 31, 2011 · Viewed 12.7k times · Source

My function is definitely working; it's tested and was at one point being recognized.

Here's the function prototype:

function [X Y] = calculateEllipse(x, y, a, b, angle)
%# Code here
end

Here's the call I'm making from the Matlab terminal:

calculateEllipse (612, 391, 107, 60, 331)

Here's the error popping out at me:

??? Undefined function or method 'calculateEllipse' for input arguments of
type 'double'.

Now, I am 100% positive I am in the same directory as the function. I even used

addpath('C:\path-to-function')

to make sure. It's just not working, and I'm baffled.

Any help is appreciated.

Answer

Richie Cotton picture Richie Cotton · Aug 31, 2011

To summarise other posts, here is a workflow for determining the cause of the problem.

  1. You mistyped the name of the function. Check the function definition and make sure it really it called calculateEllipse.

  2. You saved the function to a file named something other than the function name. Check the filename of the function and make sure it matches the function name.

  3. The folder containing the function name isn't on the MATLAB path. There are several ways to check this. Type path to see the current path, or which calculateEllipse to find the location that MATLAB is using for that file. (If there is a problem, that last command will display 'calculateEllipse' not found.. Note that addpath does not permanently update the path, so when you close down MATLAB, the path will be reset. Use savepath for this.

  4. The folder containing the function is a subdirectory of matlabroot. These folders are reserved for fully fledged toolboxes; bad things happen when you store your code here. See Bob's answer for more information.

Other useful things to check are:

  1. Can you call other functions that are stored in the same folder?

  2. If you save the function in a different folder, will it run then?