MATLAB: How to get only the subfolders of a folder

dirfilesfoldersMATLABremovesubfoldersubfolders

How do I get only the subfolders of a folder?
The "dir" command gives a struct with all the subfolders as well as all the files and '.', '..'.

Best Answer

The following code, returns a struct containing only the subfolders of a folder.
% get the folder contents
>> d = dir('foldername')
% remove all files (isdir property is 0)
>> dfolders = d([d(:).isdir])
% remove '.' and '..'
>> dfolders = dfolders(~ismember({dfolders(:).name},{'.','..'}))