Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 953
Xara Avatar asked Jul 25 '26 23:07

Xara


1 Answers

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.

like image 111
Acorbe Avatar answered Jul 27 '26 20:07

Acorbe