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

前端 未结 4 2137
独厮守ぢ
独厮守ぢ 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:35

    I don't know of any direct solutions to the problem you are having. I found a solution for a problem similar to yours, here

    List = dir('*.png');
    Name = {List.name};
    S = sprintf('%s,', Name{:});    % '10.png,100.png,1000.png,20.png, ...'
    D = sscanf(S, '%d.png,');       % [10; 100, 1000; 20; ...]
    [sortedD, sortIndex] = sort(D); % Sort numerically
    sortedName = Name(sortIndex);   % Apply sorting index to original names
    

    Differences are:

    1. You are dealing with directories instead of files
    2. Your directories have other text in their names in addition to the numbers

提交回复
热议问题