Saving and switching workspaces and contexts

19 ビュー (過去 30 日間)
John Johnson
John Johnson 2019 年 4 月 7 日
回答済み: Doug Mercer 2019 年 4 月 12 日
I have a few projects that I use MATLAB for. I would like to have a way to change the environment for each of those projects. For instance, if I’m working on EEG, I would like MATLAB to change to the appropriate folder, open the source code I had open the last time I worked on EEG, etc. When I switch to kinematics, the same scenario: change directory, open source files. (Restoring workspace variables would be a plus, but not required.)
Are there any built-in or add-on ways to do this? (I’m using macOS, if that’s a factor.)

採用された回答

Doug Mercer
Doug Mercer 2019 年 4 月 12 日
You could write script(s) to switch to a particular workspace.
You'd want to put the scripts in a folder that is always on your path (for example Documents/MATLAB).
A script might look like
function switchToEeg()
% Save your current workspace to your current working directory
evalin('base', 'save last.mat');
% Reset path to default
path(pathdef);
% Change your working directory to the folder with eeg stuff
cd('/absolute/path/to/folder/with/eeg/stuff')
% If you have a previous workspace here, open it
if exist('last.mat', 'file') == 2
load last.mat
end
% Add files you might want to call to your MATLAB path
% You can use genpath if it makes sense or write out files/folders explicitly
addpath(genpath('.'))
% Open the files you want to routinely edit
edit filename.m
% alternatively, if you want to open all m files in the current folder, you could do
files = dir('*.m');
for i = 1:length(files)
edit(files(i))
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEEG/MEG/ECoG についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by