Info

此问题已关闭。 请重新打开它进行编辑或回答。

datenum problem with conversion

2 次查看(过去 30 天)
jenka
jenka 2017-1-18
关闭: MATLAB Answer Bot 2021-8-20
I have a question. I am trying to use datenum function as below. Question: why ans1=ans2? Am I using format wrongly? Thank you!
ans1 = datenum('4:30:00 PM','HH:MM:SS PM')
ans1 =
7.3670e+05
ans2 = datenum('2:30:00 PM','HH:MM:SS PM')
ans2 =
7.3670e+05
  2 个评论
Stephen23
Stephen23 2017-1-19
Are they the same?
>> format longg
>> datenum('4:30:00 PM','HH:MM:SS PM')
ans =
736696.6875
>> datenum('2:30:00 PM','HH:MM:SS PM')
ans =
736696.604166667

回答(1 个)

Star Strider
Star Strider 2017-1-18
They’r not the same. Use the format function to display the entire number in full precision:
format long g
ans1 = datenum('4:30:00 PM','HH:MM:SS PM')
ans2 = datenum('2:30:00 PM','HH:MM:SS PM')
ans1 =
736696.6875
ans2 =
736696.604166667
  1 个评论
Jan
Jan 2017-1-19
Alternatively:
ans1 = datenum('4:30:00 PM','HH:MM:SS PM')
ans2 = datenum('2:30:00 PM','HH:MM:SS PM')
ans1 - ans2
% And:
(ans1 - ans2) * 86400

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by