Saving my own function to be used as MATLAB built-in functions

64 views (last 30 days)
I would like to write a function that can be called from anywhere regardless of my current working path, just like I use integral(...) or sin(...). How should I change the setup to be able to do this?
Saeid on 26 Apr 2018
Believe it or not, this is the first time I really need to do that.

Sign in to comment.

Accepted Answer

Ahmet Cecen
Ahmet Cecen on 26 Apr 2018
Edited: Ahmet Cecen on 26 Apr 2018
Create a startup.m file in your MATLAB user folder(usually Documents/MATLAB) then use addpath in that file.
MATLAB will execute that file everytime it starts up, meaning the paths you specify in that file will be "permenantly" available in any folder for all intents and purposes. (At least for all cases someone asking this question will likely encounter.)

More Answers (1)

the cyclist
the cyclist on 26 Apr 2018
Edited: the cyclist on 26 Apr 2018
One way is to put any such functions into a particular directory (e.g. "utilities"), and then add that directory to the search path using the addpath command. I put the addpath command in my startup.m file, so it gets called every time I start MATLAB.

Sign in to comment.


Find more on Search Path in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by