フィルターのクリア

trying to store data in a matrix using loop

2 ビュー (過去 30 日間)
Susan Santiago
Susan Santiago 2018 年 10 月 6 日
編集済み: Stephen23 2021 年 4 月 18 日
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 件のコメント
Stephen23
Stephen23 2018 年 10 月 7 日
"The first column of all these files are dates"
But what format are they in? What date does "7633" represent?

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2018 年 10 月 6 日

その他の回答 (1 件)

Stephen23
Stephen23 2018 年 10 月 7 日
編集済み: Stephen23 2021 年 4 月 18 日
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.

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by