Azzera filtri
Azzera filtri

access sequence of file with date increment

1 visualizzazione (ultimi 30 giorni)
shivani badodiya
shivani badodiya il 24 Set 2018
Risposto: Peter Perkins il 1 Ott 2018
I have sequence of files name as wrfout_2011-11-01,wrfout_2011-11-02 upto wrfout_2011-12-31 and for 2012 it will start from january wrfout_2012-01-01 to April wrfout_2012-04-30 and then it skip 6 month and then start fron wrfout_2012-11-01 to wrfout_12-12-31,so how can I read this date sequence from sequence of files.

Risposte (2)

ANKUR KUMAR
ANKUR KUMAR il 24 Set 2018
This answer is not going to specific only for WRF output files, but for all. First read all files and store their names in a variable. And sort if wish.
F=dir('wrfout*')
case_name = reshape({F.name}, [], 1);
If you want only numeric out of file names, then use
dates=cellfun(@(x) char(regexp(x,'\d*','Match')),case_name,'uni',0)
or if you numbers are on the same places in all files, then you can use
dates=cellfun(@(x) strcat(x(8:11),x(13:14),x(16:17)),aa,'uni',0)
If you want to convert into datenum format, then this example may help
A=20180924
a1=num2str(A)
datenum(str2double({a1(1:4),a1(5:6),a1(7:8)})); %for datenum format
A1=[str2double({a1(1:4),a1(5:6),a1(7:8)})] %for storing dates in vector

Peter Perkins
Peter Perkins il 1 Ott 2018
There are other ways to do this, but here's one straight-forward way:
>> dates = [datetime(2011,11,1):caldays(1):datetime(2011,11,3) datetime(2012,1,1):caldays(1):datetime(2012,1,3)]
dates =
1×6 datetime array
01-Nov-2011 02-Nov-2011 03-Nov-2011 01-Jan-2012 02-Jan-2012 03-Jan-2012
>> filenames = string(dates,'''wrfout_''yyyy-MM-dd')
filenames =
1×6 string array
Columns 1 through 5
"wrfout_2011-11-01" "wrfout_2011-11-02" "wrfout_2011-11-03" "wrfout_2012-01-01" "wrfout_2012-01-02"
Column 6
"wrfout_2012-01-03"

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by