trying to store data in a matrix using loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Susan Santiago
le 6 Oct 2018
Modifié(e) : Stephen23
le 18 Avr 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 commentaire
Stephen23
le 7 Oct 2018
"The first column of all these files are dates"
But what format are they in? What date does "7633" represent?
Réponse acceptée
Plus de réponses (1)
Stephen23
le 7 Oct 2018
Modifié(e) : Stephen23
le 18 Avr 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 commentaires
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!