3

I wrote some codes for my project in Matlab. These codes consists of some functions and a main run file which are all scripted separately and kept in a folder. When I want to run the project I must set the Matlab path to this folder and then run the main file.

Now, I want to use another toolbox in my project which is developed by a third party. As I said, I want to use this toolbox in my own project, but I can only set the Matlab path to one of these directories. I was thinking if there is a way to add this toolbox to main path of Matlab so that it can be run like other predefined functions of Matlab like fmincon.

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
Masan
  • 347
  • 1
  • 4
  • 17

1 Answers1

6

In case of the toolbox I'd add it to the main search path of Matlab. You can do this with the Set Path in the main panel:

enter image description here

Click Add with Subfolders and choose the toolbox.

For your project, I would add the folder to your main function simply by using addpath. This option is temporary! If your folder contains a set of functions you always use, you can also add it permanently as above with Set Path. But be aware to pass this folder to others, if they want to use your project.

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
  • `For your project, I would add the **folder** to your main function simply by using add path.` You mean the toolbox folder? @thewaywewalk – Masan Mar 22 '15 at 11:58
  • 2
    @Jamaisavenir No, as I understood you have a third party toolbox. I would add it permanently with **Set Path**. And then you have a project folder with your main file, for example **C:\myproject\main.m** and in this folder also is another folder with functions like **C:\myproject/myfunctions**. To use this write in the beginning of your **main.m** the line ``addpath('C:\myproject\myfunctions')``. – Robert Seifert Mar 22 '15 at 12:05