Adham shafik
Adham shafik

Reputation: 1044

Matlab 2012 doesn't run my functions properly

I wrote this m-file

function adhamm = adhamm(a,b)
    adhamm = a+b
end

and when I try to run it via MATLAB's command line by writing

a = 2;
b = 3;
adhamm(a,b);

I get this error

Undefined function 'adhamm' for input arguments of type 'double'.

Why is this?

Upvotes: 0

Views: 927

Answers (3)

Oli
Oli

Reputation: 16045

You've probably saved a variable with name adhamm. Type clear adhamm and try again.

Upvotes: 0

user85109
user85109

Reputation:

These functions were not placed in the search path for the new version. MATLAB simply does not know where to find them. However, do NOT place them in a MATLAB toolbox directory. That is not the place to put your own functions. Put them in a separate directory that you will tell MATLAB how to find using the path tools. (If you cd to that directory, MATLAB will automatically look there, but that is not a good solution.)

You need to learn about the search path in matlab, and the tools matlab has to maintain search paths. Thus, addpath, savepath, rmpath, pathtool.

Upvotes: 1

mike
mike

Reputation: 98

you saved your function with the name adhamm.m, right? Then try to execute the function within the folder of adhamm.m.

Upvotes: 0

Related Questions