Running functions from initial working function when in another subfolder?

조회 수: 8 (최근 30일)
Hi there,
I noticed that under preferences--> general the user can set the initial working folder for matlab. My friend's computer is set to "based on startup rules" and my is set to a syncd gDrive folder for convenience between my workstations. On my friend's computer he is able to store functions in his startup (initial working) folder i.e.user/docs/MATLAB and RUN THEM from any subfolder of that root. I on the other hand receive an error when I try to do this same thing user a another specified folder selected in the general preferences area.
I would like to have the same flexibility with my function placement as my friend but use the gDrive folder instead of the default user/doc/MATLAB. This allows function calls by just "function name (xx,xxx,..)" instead of specifying the full path each time.
Does anyone know a way I can make this work?
Thanks for your help!!! It is much appreciated!

채택된 답변

Image Analyst
Image Analyst 2015년 9월 4일
Why not just put this in your startup.m file:
addpath('g:\folder');
savepath;
  댓글 수: 4
Steven Lord
Steven Lord 2015년 9월 4일
You can put whatever you want in your startup.m file. A mildly annoying April Fools' joke would be to modify someone's startup.m to include the command " quit force " so MATLAB shuts down on startup. [You'd have to edit startup.m in a text editor to remove the offending command.]
As listed in the See Also section of the startup.m documentation page, the finish.m file is the equivalent of startup.m for doing something when MATLAB exits rather than when MATLAB starts.
Bora Eryilmaz
Bora Eryilmaz 2015년 11월 12일
편집: Bora Eryilmaz 2015년 11월 12일
It is enough to run the accepted answer once since it will save the specified folder on your MATLAB path. You don't need to rerun it from startup.m every time you start MATLAB.
You friend can run his code from anywhere because the folder "user/docs/MATLAB" is automatically on the MATLAB path, whereas yours was not.

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

추가 답변 (0개)

카테고리

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