Change of data format
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I have a *.txt file with data in the following format (say, file1):
00Z01JAN1948 0.00579036
06Z01JAN1948 0.00346197
12Z01JAN1948 0.00728858
18Z01JAN1948 0.0145886
00Z02JAN1948 0.00592358
06Z02JAN1948 0.00298858
12Z02JAN1948 0.00788106
18Z02JAN1948 0.0123543
00Z03JAN1948 0.0219563
06Z03JAN1948 0.023932 (and so on up to 2014...)
So, the first column contains hour (first two values), (Z stands for zullu time, I don't need that) and the rest is date. The second column contains some data (pressure gradients).
The second file (say, file2) contains dates in the format:
1011949 0 %(this would be Jan 1st, 1949 at 00 h)
1011949 6 %(this would be Jan 1st, 1949 at 06 h)
1011949 12
1011949 18
2011949 0 %(this would be Jan 2nd, 1949 at 0 h)
2011949 6 (and so on until 2010)
file1 and file2 are not the same in size; file1 is longer and has all dates from 1948 to 2014 while file2 has some of dates from 1949 to 2010.
I need to extract pressure gradient valus from file1, but only for the dates (and hours) given in file2. So it would be like this: 1011949 0 pressure gradinet value for that date
1011949 6 pressure gradinet value for that date
1011949 12 pressure gradinet value for that date
1011949 18 pressure gradient value for that date
Please, could you help me with this? I am not sure how to transfer dates from one format to other so that I compare two sets of data.
Thanks, Djordje
0 Commenti
Risposta accettata
dpb
il 1 Ago 2014
Read the two files and convert to Matlab datenum datenums...
00Z01JAN1948 0.00579036
Format for first would be
fmt1='%s %f';
c=textscan(fid,fmt1);
The 'Z' adds a minor complication -- you can approach one of two ways; probably as simple as any is to simply replace it in place in the call...
dn=datenum(strrep(c(1),'Z',''),'hhddmmmyyyy');
dn =
1.0e+05 *
7.1149
7.1149
7.1149
>> datestr(ans)
ans =
01-Jan-1948 00:00:00
01-Jan-1948 06:00:00
01-Jan-1948 12:00:00
>>
The second is similar except the date format string uses only the one/two character for the day so
dn2=datenum(c2(1),'dmmyyyy');
Then for the values from the first file in the second,
pselect=c{2}(ismember(dn2,dn);
3 Commenti
Più risposte (1)
Vedere anche
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!