How to force Matlab to read files in a folder serially?

前端 未结 4 2070
独厮守ぢ
独厮守ぢ 2021-01-23 22:33

I have files in a folder that are numbered from writer_1 to writer_20. I wrote a code to read all the files and store them in cells. But the problem is

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-23 22:45

    Here is a slightly different way (edited to fix bug and implement suggestion of @Divakar to eliminate for loop)

    folders = dir(Path_training);
    folders(ismember( {folders.name}, {'.', '..'}) ) = [];
    
    %// Get folder numbers as cell array of strings
    folder_nums_cell = regexp({folders.name}, '\d*', 'match');
    
    %// Convert cell array to vector of numbers
    folder_nums = str2double(vertcat(folder_nums_cell{:}));
    
    %// Sort original folder array
    [~,inds] = sort(folder_nums);
    folders = folders(inds);
    

提交回复
热议问题