Access m-files in a subfolder without permanently adding it to the path

后端 未结 2 613
眼角桃花
眼角桃花 2020-11-27 22:26

I have downloaded a toolbox with many files in many subfolders (spatial-econometrics toolbox) for use on one particular project and I don\'t want to add it to the path becau

2条回答
  •  野性不改
    2020-11-27 22:30

    I use the following to keep my functions in a separate 'functions' folder in the same directory as the main script. As long as you know the path to the toolbox functions, this should work for you.

    % Add path (at beginning of script)
    added_path = [pwd,'/functions']; %change to: added_path = '/path' for your required path
    addpath(added_path);
    
    % Remove path (at end of script/script clean-up)
    rmpath(added_path);
    

    You may want to look at genpath() to get those long and windy toolbox paths in a manageable way.

提交回复
热议问题