Reputation: 139
Where can i save my document "function.m", so i can call this function from any code in any path of my pc? I already made some custom functions, but i dont know where to save those codes to be able to call them from any part.
Upvotes: 2
Views: 368
Reputation: 1040
Alternatively to Adriaan's best practice answer, the fastest option is to save your function.m
in the %USERPROFILE%/Documents/MATLAB
directory on your PC ($home/Documents/MATLAB
on Linux and Mac). This directory is on your MATLAB Search Path by default. This might be an acceptable solution if you use the function commonly across different projects.
Finally, there is a "manual" solution: Execute pathtool
in MATLAB, add the directory containing your function.m
via the GUI and hit save.
Upvotes: 0
Reputation: 18177
Save them in a logical place where you can find them back. Then, use addpath
to add that folder to MATLAB's search path, i.e. when you use a function it will try that folder as well to find it.
You can do this either per script, or edit startup.m
with this, so that it's automatically included when MATLAB starts.
Upvotes: 2