How to store Matlab datetime data type in hdf5

조회 수: 10 (최근 30일)
ET
ET 2019년 12월 24일
댓글: Eric Sofen 2020년 1월 24일
Hi,
I'm new to using the hdf5 data format and am wondering how best to store timestamp information in an efficient manner. The process for me has been that the raw data files are in ascii, I then have a script which reads them in to matlab data structure, but one of the slower steps is converting the ascii timestamps (e.g. '2019-12-25T17:15.1235') into matlab datetime.
Ideally, I'd like to switch over to using hdf5 instead of ascii for the raw data sets, but would like to have an efficient way of writing/reading timestamp data. Note that the data can have high sample rates, so the timestamps can have several decimal places for the seconds.
thanks!

채택된 답변

Eric Sofen
Eric Sofen 2020년 1월 10일
I don't think HDF5 has its own definition of a date/time type and you can't store MATLAB datetimes directly in HDF5. There are occasional references in the HDF5 documentation to a date and time type or "H5T_TIME", but it appears that it has not been fully implemented. I think the standard approach for HDF5 or netCDF files is to store times as an epoch (usually expressed in text) and a numeric offset. You'll want to choose your epoch and offset wisely to avoid floating point precision issues (e.g. if you've got microsecond-precision data, don't use "seconds since 0 CE" as your epoch). The datetime/convertTo method can help with the conversion from datetime.
This example illustrates some of the process of going the other direction (from HDF5 to MATLAB).
  댓글 수: 2
ET
ET 2020년 1월 24일
편집: ET 2020년 1월 24일
Thanks, I was considering both text and epoch approaches but was wondering from a matlab perspective about the the most efficient (fastest) way of converting them to datetime on read into matlab or on write to the hdf5 file. I could run a few tests to check myself but if someone already had some experience on best practice it could save me some effort.
Eric Sofen
Eric Sofen 2020년 1월 24일
Converting to and from an epoch time is likely faster than converting from text.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 HDF5에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by