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

조회 수: 107 (최근 30일)
Saeid
Saeid 2018년 4월 26일
댓글: Saeid 2018년 4월 27일
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?
  댓글 수: 2
Jan
Jan 2018년 4월 26일
편집: Jan 2018년 4월 26일
You are a member of this forum for 2 years now and asked 44 questions. And this is the first time you want to add a user defined folder to the path? I cannot image how you can work with Matlab without saving files to folders in the path.
Saeid
Saeid 2018년 4월 26일
Believe it or not, this is the first time I really need to do that.

댓글을 달려면 로그인하십시오.

채택된 답변

Ahmet Cecen
Ahmet Cecen 2018년 4월 26일
편집: Ahmet Cecen 2018년 4월 26일
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.)

추가 답변 (1개)

the cyclist
the cyclist 2018년 4월 26일
편집: the cyclist 2018년 4월 26일
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
Jan
Jan 2018년 4월 27일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by