trying to store data in a matrix using loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Susan Santiago
am 6 Okt. 2018
Bearbeitet: Stephen23
am 18 Apr. 2021
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 Kommentar
Stephen23
am 7 Okt. 2018
"The first column of all these files are dates"
But what format are they in? What date does "7633" represent?
Akzeptierte Antwort
Weitere Antworten (1)
Stephen23
am 7 Okt. 2018
Bearbeitet: Stephen23
am 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!