Saving my own function to be used as MATLAB built-in functions
Afficher commentaires plus anciens
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?
Réponse acceptée
Plus de réponses (1)
the cyclist
le 26 Avr 2018
Modifié(e) : the cyclist
le 26 Avr 2018
2 votes
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.
4 commentaires
Jan
le 26 Avr 2018
Instead of putting addpath to the startup file, you can use savepath or the GUI pathtool to store the folder permanently.
Saeid
le 26 Avr 2018
Jan
le 27 Avr 2018
A correct usage of savepath is:
addpath('D:\Documents\MATLAB\Examples', '-end');
savepath
Then the path is saved to the matlabroot folder, but this requires admin privilegs. Therefore it might be better to follow the advice given in the warning message: save the pathdef.m file to your startup folder - the folder which is active initially.
It is not clear, why the saving failed in your case. Is the folder existing and do you have write privileges?
Saeid
le 27 Avr 2018
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!