Why can't Matlab see my function?

13,802

Solution 1

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?

Solution 2

Adding to what Jeff said; another possibility is that you placed the function somewhere inside of your MATLAB installation. By default MATLAB does't re-search its own file structure for new files; it assumes that its internal file structure remains unchanging. Make sure that you're saving the file (which, as Jeff pointed out, must be named calculateEllipse.m) somewhere outside of your MATLAB installation.

See https://www.mathworks.com/help/matlab/matlab_env/toolbox-path-caching-in-the-matlab-program.html, or go to the MathWorks web site and search for

path cache

for more information.

Solution 3

The key to this problem is this: %Has no license available. This implies that a function in the directory of the function you are trying to use has the same name as a function in a toolbox you do not own. MATLAB by default disables the whole directory and not just the function of the same name in a toolbox you do not own. Here is an example:

files in directory:

myfunction.m
scoobydoo.m
blackman.m

If I do not own the "Signal processing toolbox," then blackman.m will disable the whole directory.

Solution 4

I can think of a couple of reasons this could happen.

First, as Jeff said, you could have named the file 'calcEllipse.m' instead of 'calculateEllipse.m'. In which case you need to rename the function to be the same as the m file you saved.

Second, you have not added the correct path. There is no reason for this to give an error to my knowledge otherwise. Double check that you have added the path to the m file that is being saved. An easy way to check is if you type in 'calculateEll' and then press tab, does the autocomplete work? If not you are out of the path.

Hope it is one of those thing you can quickly fix!

Share:
13,802
user920761
Author by

user920761

Updated on September 05, 2022

Comments

  • user920761
    user920761 over 1 year

    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.

  • user920761
    user920761 over 12 years
    Thank you for your help and I'm sorry for the very late response. I typed in "which calculateEllipse" and it gave me the path but said %Has no license available. I then tried to copy the code as a new function and gave it a different name and received the same error. Any suggestions?