I have created my own mfile and would like to add it permanently lie built in functions so that I dont have to specify path. Is there a way to do it?
2 Answers
You should store your .m
file (either script
or function
) in a folder belonging to the MatLab search path
.
To add your own folder to the MatLab search path
you can use eiterh:
the
Set Path
tool, available on the MatLabHome toolbar
use the buil-in function
path
(from theCommand Window
or, for example, as part of a script)
E. g.
path(path,'c:\my_folder\my_sub_folder')
Hope this helps.

- 5,090
- 129
- 31
- 36
Write your file and save it and then add the containing folder to the MATLAB search path. You do not need to look for it every time.
addpath('c:/matlab/myfiles')
Note: your filename should not exist within MATLAB, otherwise your file would be the default one, when you call that command.
You can also do most of the work from command-line: First, create a folder,
mkdir('c:/matlab/myfiles')
Add it to the top of your search path,
addpath('c:/matlab/myfiles')
and then save the search path for future MATLAB sessions
savepath c:/matlab/myfiles/pathdef.m

- 6,482
- 6
- 36
- 55