How can I maintain multiple MATLAB path setups and switch between them easily?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 20 de Abr. de 2017
Respondida: MathWorks Support Team
el 5 de Mayo de 2017
In my work I often need to switch between two "environments" which correspond to different MATLAB path settings. The path setups are mutually exclusive because the same function may be present in both environments. For example the directory structure is:
/release_folder
/myFunc.m
/development_folder
/myfunc.m
How can I switch between these environments quickly, easily, and without creating issues related to 'restoredefaultpath' ?
Respuesta aceptada
MathWorks Support Team
el 7 de Jul. de 2017
Below is an example of how one might accomplish this. The key points of the approach are:
1. In order to "reset" the path before switching streams use 'pathdef' to load the path MATLAB started with instead of using 'restoredefaultpath'. This keeps support packages on the path.
2. Create a helper function for each stream which sets up the path correctly for that stream.
3. Keep the the helper functions on the path so that it is easy to switch streams.
Example Code:
startup.m - Put the helper functions on the path when starting MATLAB.
if ~isdeployed % deployed applications will not run the code below
% This folder contains useDevelopmentPath and useReleasePath
addpath('H:\Documents\MATLAB\pathtools');
end
pathtools\useDevelopmentPath.m - sets up path for development stream
function useDevelopmentPath
path(pathdef);
addpath('H:\Documents\MATLAB\pathtools'); % For useDevelopmentPath and useReleasePath
addpath('H:\Documents\MATLAB\development_folder'); % add all folders needed for development stream
...
end
pathtools\useReleasePath.m - sets up path for release stream.
function useReleasePath
path(pathdef);
addpath('H:\Documents\MATLAB\pathtools'); % For useDevelopmentPath and useReleasePath
addpath('H:\Documents\MATLAB\release_folder');% add all folders needed for release stream
...
end
Using these helper functions would look like:
>> useDevelopmentPath
>> myFunc
myFunc: Development Version
>> useReleasePath
>> myFunc
myFunc: Release version.
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!