Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import/include MATLAB functions?

I have some MATLAB functions defined in .m files and I'd like to import them into MATLAB (as in I'd like to be able to call them as I do a built-in function). How can I do this?

like image 527
Krt_Malta Avatar asked May 15 '10 19:05

Krt_Malta


People also ask

How do you import a function into a MATLAB script?

If you use the import command in a MATLAB® function, add the corresponding . NET assembly before calling the function. For example, the following function getPrinterInfo calls methods in the System.

What are MATLAB packages?

Packages are special folders that can contain class folders, function, and class definition files, and other packages. The names of classes and functions are scoped to the package folder. A package is a namespace within which names must be unique. Function and class names must be unique only within the package.


2 Answers

If the folder just contains functions then adding the folders to the path at the start of the script will suffice.

addpath('../folder_x/'); addpath('../folder_y/'); 

If they are Packages, folders starting with a '+' then they also need to be imported.

import package_x.* import package_y.* 

You need to add the package folders parent to the search path.

like image 151
Morgan Avatar answered Oct 11 '22 15:10

Morgan


You have to set the path. See here.

like image 41
Artefacto Avatar answered Oct 11 '22 15:10

Artefacto