Hello Community,
Recently there was a request from an user who wanted to get the subfolders (and only them) within a certain directory. Generally speaking people want to get the list with files given a certain extension - for example thinking about '.xlsx', it can be simply obtained by using:
xlsx_files = dir('*xlsx'); But how to get the subfolders? Below there is a simple solution that is totally general, working in any directory and without loops:
files = dir(); %Listing of the current directory files dirFlags = [files.isdir]; %Selecting directories indexes in the structure subFoldersC = files(find(dirFlags)); %Selecting only the directories in the structure subFoldersStruct = subFoldersC(3:end); %Deleting '.' and '..' directories subFoldersCell = struct2cell(subFoldersStruct); %Converting structure to cell data subFoldersCell = subFoldersCell(4,:) %Getting a cell of desired subfolders
Generally speaking I prefer to work with cells, but if the user wants a structure itself, the clean solution stops at the fourth line - subFoldersStruct is enough (please don't forget to use '.name' to access it then). Thanks @Roberta Varela for the talk. 
Hope it helps.