How to run two MATLAB instances simultaneously wit

2019-03-31 23:22发布

I'm developing my own brain imaging toolbox that runs under MATLAB & SPM8, and at the same time I have a git clone'd version of my own toolbox code directory (local git repository) for running analyses, this setup is created according to Kevin Reid's answer on How to work simultaneously on several different versions of files with git?, which solved a part of the problem (how to have different versions of same .m file accessible at the same time, and still synchronizable by using git fetch or git pull).

However, my MATLAB install is in neither of these git directories; it's installed normally in /usr/local/MATLAB/R2012a/. MATLAB looks for functions according to pathdef.m, which is stored in which pathdef (/usr/local/MATLAB/R2012a/toolbox/local/pathdef.m) as a regular function. So I cannot have two MATLAB instances running simultaneously so that they had different pathdef's, at least not by modifying pathdef.m file.

Of course MATLAB has to know beforehand where to look for pathdef.m to define the path. Is there a way to change pathdef.m lookup path eg. by some MATLAB command line argument or from MATLAB console? Or by some other means, so that I could have two MATLAB instances running simultaneously with different pathdef's? Or should I install MATLAB in two different directories? I'm interested in all kinds of solutions for this problem.

2条回答
老娘就宠你
2楼-- · 2019-04-01 00:08

Let me offer an alternative approach. It involves creating shortcuts inside the MATLAB IDE.

Simply create two shortcuts, each include something like:

addpath(genpath('/path/to/project_branch'))   %// add branch (and subfolders) to MATLAB path
cd('/path/to/project_branch')                 %// navigate to directory

(Explanation: The call to addpath will not save the changes system-wide, but will only persist for the current session, unless you call savepath)

Now whenever you start a new MATLAB session, and you decide to work on one or the other branch, simply click the corresponding shortcut and start hacking away...

Better yet, if you consider one branch as stable and the other as dev, you can add the stable one to the path permanently, and selectively add the development version on the top of the path addpath('...','-begin') using a shortcut, thus shadowing the other branch for the current session only.

screenshot

查看更多
【Aperson】
3楼-- · 2019-04-01 00:08

yes, there is. Set the environment variable MATLABPATH before starting matlab (from a terminal)

export MATLABPATH=/yourdir
查看更多
登录 后发表回答