list the subfolders in a folder - Matlab (only subfolders, not files)

后端 未结 4 1835
心在旅途
心在旅途 2020-12-25 12:13

I need to list the subfolders inside a folder using Matlab. If I use

nameFolds = dir(pathFolder), 

I get . and ..

4条回答
  •  时光说笑
    2020-12-25 12:48

    And to effectively reuse the first solution provided in different scenario's I made a function out of it:

    function [ dirList ] = get_directory_names( dir_name )
    
        %get_directory_names; this function outputs a cell with directory names (as
        %strings), given a certain dir name (string)
        %from: http://stackoverflow.com/questions/8748976/list-the-subfolders-
        %in-a-folder-matlab-only-subfolders-not-files
    
        dd = dir(dir_name);
        isub = [dd(:).isdir]; %# returns logical vector
        dirList = {dd(isub).name}';
        dirList(ismember(dirList,{'.','..'})) = [];
    
    end
    

提交回复
热议问题