Filter löschen
Filter löschen

trying to store data in a matrix using loop

2 Ansichten (letzte 30 Tage)
Susan Santiago
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
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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 6 Okt. 2018

Weitere Antworten (1)

Stephen23
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.

Kategorien

Mehr zu Shifting and Sorting Matrices 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!

Translated by