Time difference calculated with datenum

6 ビュー (過去 30 日間)
Xin Ru
Xin Ru 2014 年 7 月 23 日
コメント済み: Xin Ru 2014 年 7 月 24 日
Hi,
This is my first time posting in the mathworks forums, so hello everybody!
Anyway, this is my question:
I have a time series of data at intervals of 20 min, and am running a script to check if all the intervals are equal (i.e. 20 min between each data set). To check the intervals, I have something like this:
diff_dates=diff([time series]) % [time series] is in matlab serial date number format
if sum(diff_dates-diff_dates(1))==0 % this tells me if the intervals are equal
The problem is, in checking the data manually the intervals seem equal, but diff_dates-diff_dates(1) gives me a non zero vector like this:
1.0e-09 *
[
0
0
0
0
0
0
0.116415321826935
0
0
0
0
0
0
0
0
0.116415321826935
0
0
0
0
0
0
0
0
0.116415321826935]
and so on...
By observation, the non-zero differences repeat every 9 elements and in tracing back, they correspond to the following times:
15:55:39 minus 15:35:39
18:55:39 minus 18:25:39
21:55:39 minus 21:35:39
and so on...Basically every 3 hours. Also, I tried testing with different hours, minutes and seconds and strangely the difference only appears for those specific times listed above. Changing the seconds value does not have any effect on the calculated difference.
I managed to solve this problem by working in datevec format rather than in serial date format, but its really bugging me what's causing this inconsistency. My idea is that the matlab serial date format is expressed as a fraction of a day and the precision of the datenum function (which I had used to convert my data to serial date) is causing this.
Any experts around here willing to shed some light? Thanks in advance!
-XRT

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 7 月 23 日
The difference is very small: 1.0e-09, it's probably due to the way your data are stored. Look at this link http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
  1 件のコメント
Xin Ru
Xin Ru 2014 年 7 月 24 日
Ok, thanks for the answer!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTime Series Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by