Xara
Xara

Reputation: 9098

Matlab: Calling user defined function

I am creating a user defined function in this manner

   function y=add(a)

   y=a*a;

Now, this function is in a separate .m file.

I want to make use of this function but I am not getting it how to call it

Do I need another .m file to call it? and #include the above .m file?

Upvotes: 3

Views: 25018

Answers (1)

Acorbe
Acorbe

Reputation: 8391

First, you need to name the file add.m (i.e. exactly the same name your function has) and you can place it anywhere in the current matlab path (your current working directory is fine).

Second, you should call your function doing (e.g.) y=add(5) either from command line or from another matlab script/function.

In those scripts there's no need for further #include-like stuff, provided, again, add.m is in your working path.

Upvotes: 7

Related Questions