- the first appearance of exactly fourteen consecutive digits surrounded by underscore, "_", represents date and time.
- the string of digits honors the pattern, 'yyyymmddHHMMSS'
how read a date-time from HDF5 file
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
pruth
am 29 Okt. 2015
Bearbeitet: per isakson
am 4 Nov. 2015
hi i have HDF5 files there names are like
GOME_O3-NO2-NO2Tropo-BrO-SO2-H2O-HCHO_L2_20070123202633_051_METOPA_01366_DLR_03.HDF5
i want read this string and want only date (2007-01-23-20:26:33)
how get only date and time excluding other character.????
0 Kommentare
Akzeptierte Antwort
per isakson
am 3 Nov. 2015
Bearbeitet: per isakson
am 4 Nov. 2015
How to extract date and time from a string? (In this case the string happens to be the name of a HDF5-file.)
First something simple
str = 'GOME_O3-NO2-NO2Tropo-BrO-SO2-H2O-HCHO_L2_20070123202633_051_METOPA_01366_DLR_03.HDF5';
dti = regexp( str, '\d{14}', 'match', 'once' );
datestr( datenum( dti, 'yyyymmddHHMMSS' ), 'yyyy-mm-dd HH:MM:SS' )
ans =
2007-01-23 20:26:33
This code assumes that the first appearance of fourteen consecutive digits represents date and time. However, is that guaranteed? If not, is there some other characteristics of the string that can be used? Furthermore, is it guaranteed that the string of digits honors the pattern, 'yyyymmddHHMMSS'?
It's possible to create a regular expression, which take advantage of the fact that not all digits can appear in all positions, e.g minutes and second are constrained by the interval [00,59].
 
A bit more selective:   Assume that it's guaranteed that
If so replace the expression, '\d{14}', by '(?<=_)\d{14}(?=_)'
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu HDF5 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!