0

When I convert given date-number '2011-01-06 0:45' by

datenum('2011-01-06 0:45','yyyy-mm-dd HH:MM')

I get

734509.0313

as date-number.

But when I generate a vector of date-numbers using

begin_date_time=datenum('2011-01-06 00:00:00','yyyy-mm-dd HH:MM:SS');
str_next_date=strcat('2011-01-06',32,'00:15:00');
next_date_time=datenum(str_next_date,'yyyy-mm-dd HH:MM:SS');
interval=next_date_time-begin_date_time;
end_date_time=datenum('2011-12-31 00:00:00','yyyy-mm-dd HH:MM:SS');
full_data_time_steps=begin_date_time:interval:end_date_time;

The fourth date-number in the vector 'full_data_time_steps' is

734509.0312.

But it corresponds to the same date-time '2011-01-06 0:45'. I am not sure why this is happening and how to solve this? Any help is appreciated.

Abhinav Gupta
  • 187
  • 1
  • 9

1 Answers1

2

Are you sure you are looking at them correctly? When I do

format long g % to make sure we see all the decimals 

datenum('2011-01-06 0:45','yyyy-mm-dd HH:MM')

ans =

              734509.03125

begin_date_time=datenum('2011-01-06 00:00:00','yyyy-mm-dd HH:MM:SS');
str_next_date=strcat('2011-01-06',32,'00:15:00');
next_date_time=datenum(str_next_date,'yyyy-mm-dd HH:MM:SS');
interval=next_date_time-begin_date_time;
end_date_time=datenum('2011-12-31 00:00:00','yyyy-mm-dd HH:MM:SS');
full_data_time_steps=begin_date_time:interval:end_date_time;
full_data_time_steps(4)

ans =

              734509.03125

I get the same.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • Yeah. When I do intersect(full_data_time_steps,datenum('2011-01-06 0:45','yyyy-mm-dd HH:MM')). I get empty matrix. They look same after rounding off. – Abhinav Gupta Aug 06 '18 at 14:40
  • @AbhinavGupta you are right, they are `datenum('2011-01-06 0:45','yyyy-mm-dd HH:MM')-full_data_time_steps(4) = 1.16415321826935e-10` in difference, however that is withing floating point accuracy (in fact just there). You may want to [read more about comparing floating point values](https://stackoverflow.com/questions/686439/why-is-24-0000-not-equal-to-24-0000-in-matlab) – Ander Biguri Aug 06 '18 at 14:43
  • @AbhinavGupta consider accepting the answer as valid if it helped you. – Ander Biguri Aug 15 '18 at 14:22