0

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?

rsujatha
  • 103
  • 4

2 Answers2

0

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 MatLab Home toolbar

  • use the buil-in function path (from the Command Window or, for example, as part of a script)

E. g.

path(path,'c:\my_folder\my_sub_folder')

Hope this helps.

il_raffa
  • 5,090
  • 129
  • 31
  • 36
0

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
NKN
  • 6,482
  • 6
  • 36
  • 55