How to compare datenum variables
Show older comments
Hello,
I have the following problem. I should compare some timestamps I have read from an excel file. Basically what I do is creating a vector containing this timestamps converted using the "datenum" command. If i then for example try to visualize the value of the variable, I get the following result on the console:
datenum(textdata{1})
ans =
7.3450e+005
>> datestr(ans)
ans =
01-Jan-2011 00:00:06
until this point I get it perfectly.
Now, if I have another timestamp which is for example:
01-Jan-2011 00:00:01
and I convert it to a numdate, i get the same result due to the precision which matlab uses to visualize my variable:
datenum(textdata2{1})
ans =
7.3450e+005
now if I wanna compare them, I was guessin, I can just make a simple if test:
a = 01-Jan-2011 00:00:06; b = 01-Jan-2011 00:00:01;
if a == b disp ('equal') elseif a > b disp ('greater') else disp('smaller') end
greater
So up to this point is everything ok.
After that i increase b of the right quantity to make it the same as a:
b = b + (5/(3600*24)); %now b is 01-Jan-2011 00:00:06;
if a == b disp ('equal') elseif a > b disp ('greater') else disp('smaller') end
smaller
What is happening here? why I don´t get that they are the same? For instance this test gives me 'equal' only if I directly assign a = b.
How can I manage this situation?
Accepted Answer
More Answers (0)
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!