3

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?

Xara
  • 8,748
  • 16
  • 52
  • 82

1 Answers1

8

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.

Acorbe
  • 8,367
  • 5
  • 37
  • 66