36

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?

gnovice
  • 125,304
  • 15
  • 256
  • 359
Krt_Malta
  • 9,265
  • 18
  • 53
  • 91

4 Answers4

33

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.

Morgan
  • 19,934
  • 8
  • 58
  • 84
4

You have to set the path. See here.

Morgan
  • 19,934
  • 8
  • 58
  • 84
Artefacto
  • 96,375
  • 17
  • 202
  • 225
3

You should be able to put them in your ~/matlab on unix.

I'm not sure which directory matlab looks in for windows, but you should be able to figure it out by executing userpath from the matlab command line.

LordOphidian
  • 178
  • 9
2

Solution for Windows

Go to File --> Set Path and add the folder containing the functions as Matlab files. (At least for Matlab 2007b on Vista)

Hermann Döppes
  • 1,373
  • 1
  • 18
  • 26
Krt_Malta
  • 9,265
  • 18
  • 53
  • 91