How to find the same date when the serial datenum is slightly off

I'm looking to find a specific date within a larger matrix, however the datenum command returned two slightly different values for the same date causing the find function to return a null matrix. In context: these two indicies are the identical date 2/21/11 19:05:00 yet a numerical comparison returns a zero: tseries(10141) == data_series(1) ans = 0 K>> tseries(10141) ans = 7.345557951388889e+005 K>> data_series(1) ans = 7.345557951388890e+005 the actual numerical difference is tiny (1*10^-8), but the find command nonetheless won't work because the numbers aren't exactly equal. Is there any workaround to this issue?
Thanks, Munan Xu

댓글 수: 1

also the difference is not consistent across the entire matrix, so I cannot just add a constant to one matrix or the other

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

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 2월 24일
Index the result in the followin way:
idx = abs(dates1 - dates2) < 1e-4
Set the tolerance on the RHS.
Oleg

댓글 수: 1

To get the seconds you can decrease the tolerance to 1/86400.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by