Running functions from initial working function when in another subfolder?

8 ビュー (過去 30 日間)
Noel Puldon
Noel Puldon 2015 年 9 月 4 日
編集済み: Bora Eryilmaz 2015 年 11 月 12 日
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 Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by