Adding subfolders to the Matlab path

 Hi again! I have been away from the blog for the last weeks because of a small trip to Italy and some days with the flu, but now I am back at posting in this blog. Today's post it is a little tip for Matlab users. 

The issue: I have often been confronted with the problem that sometimes I want to access code that is stored in folders and subfolders inside the current folder. Or sometimes I download Github code that has functions stored inside subfolders. I used to avoid organizing and storing my functions inside subfolders because of this problem. Or I would have to find all subfolders and add them to the matlab path one by one. 

Solution Today i found out that there is a Matlab function called genpath that generates a list of all subfolders and its children. This can be used to add both the current folder and all subfolders under it to your matlab path. You can check a list of subfolders by using:

    P = genpath(mainfolder);

or you can add the current folder and all its children folders by simply typing: 

    addpath(genpath(pwd))

Simple, but effective.


Kommentarer

Populære innlegg fra denne bloggen

Opening Zeiss czi file format mosaic files in Matlab using bio-formats

Possible solution for problems opening confocal files from Zeiss LSM 880 in Neurolucida 360 environment

Opening multileveled TIFF images in Matlab