trying to store data in a matrix using loop

1 view (last 30 days)
so I have 42 data files with names pretty much the same for example "7633_Flux_AmerifluxFormat_0(1)" and then the only thing that changes throughout the file names is the 2 numbers at the end. I would like to run a loop using dir (preferably) that sorts the files into a matrix by chronology. the file names are not in that order. The first column of all these files are dates. They have to be converted to a string and then a serial date number. I want to know how to make a loop that sorts files into a matrix by serial date number? I know this is a lot but any help or advice would be appreciate as I don't know where to begin
  1 Comment
Stephen23
Stephen23 on 7 Oct 2018
"The first column of all these files are dates"
But what format are they in? What date does "7633" represent?

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 6 Oct 2018

More Answers (1)

Stephen23
Stephen23 on 7 Oct 2018
Edited: Stephen23 on 18 Apr 2021
Download my FEX submssion natsortfiles:
Use it like this:
D = 'folder where your files are stored';
S = dir(fullfile(D,'*.txt')); % pick appropriate file extension
S = natsortfiles(S); % alphanumeric sort by filename
for k = 1:numel(S)
F = fullfile(D,S(k).name)
... your code
end
Note that natsortfiles also lets you specify the number recognition, e.g. if the dates are two digits for the month and two digits for the day of the month, then you can tell it that, so that those values will be sorted separately:
S = natsortfiles(S,'\d{2}');
Read the help for more information and examples.

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!