open so many files with name of time series in order

1 回表示 (過去 30 日間)
Hamideh
Hamideh 2014 年 7 月 4 日
コメント済み: dpb 2014 年 7 月 5 日
Hello I have many text files with name of time series from 1998 until now with hourly time step. The name of files is like this: xmrg0101199800z (xmrgddmmyyyyhhz) xmrg0101199801z xmrg0101199802z . . xmrg0201199800z xmrg0201199801z . . xmrg0307201400z
xmrg and z are constant in the name of each file but hour, day, month and year change in order. I would like to open and import them open the through a subroutine. Can any one help me for this? Thanks Hamideh

回答 (2 件)

dpb
dpb 2014 年 7 月 4 日
編集済み: dpb 2014 年 7 月 5 日
Try sotoo (caution, aircode, not tested)...
d=dir('xmrg??????????z.*'); % return the list of all
dd=strvcat(d(:).name); % make a character array of the names
dd=dd(:,5:14); % strip out the date string characters
dn=datenum(dd,'ddmmyyyyhh'); % turn to datenums
[~,ix]=sort(dn); % get sorted index
for i=1:length(d)
dat=importdata(d(ix(i)).name);
...
Of course, if these files were created on their namesake day and time, you could use the datenum value directly from the returned directory structure rather than from the file name itself. That presumes the datestamps haven't been munged on, of course.

Image Analyst
Image Analyst 2014 年 7 月 5 日
  3 件のコメント
Image Analyst
Image Analyst 2014 年 7 月 5 日
You're right. Most of the time the OS returns the files in alphanumeric order but it's not guaranteed so you do need to sort to make sure, either parse the date from the filename, or get it from the datenum field of the directory structure, both of which you pointed out. If the two dates don't agree, you might have to make a decision as to why. The FAQ code can then be used after the list of filenames has been sorted.
dpb
dpb 2014 年 7 月 5 日
OK, just thought I'd note that since the FAQ doesn't address the order issue that perhaps you'd missed noticing that--I can't count the times I've somehow missed the obvious in a query...

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

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by