year function does not read properly

2 次查看(过去 30 天)
Sina Kian
Sina Kian 2019-11-24
评论: Guillaume 2019-11-24
dear friends,
I need to use year function. in excel file I prepared the data in date format. Then I changed it to number and save. Then the data is imported to Matlab. The true value of year(A(1,1)) is 2005 but matlab gives me 105.
Can anyone help?
Best Regards
  1 个评论
Guillaume
Guillaume 2019-11-24
The year function works fine so there must be a problem with what you're doing. Unfortunately, it's not very clear, so please attach a demo excel file and show us the code you've been using.

请先登录,再进行评论。

回答(1 个)

Stijn Haenen
Stijn Haenen 2019-11-24
编辑:Guillaume 2019-11-24
year(input) tells you in which year the day of the input is, where the input is the day number, starting from first of january 1BC. So the first 366 days are in year 0. Day number 728647 for example is 19-Dec-1994, so year(728647)=1994.
Stijn's other answer added to the first answer (guillaume):
In excel, the first day is the first of january 1900, i think.
  1 个评论
Guillaume
Guillaume 2019-11-24
Please stick to one answer. You can edit your answer or comment on it.
"so year(728647)=1994." Hum,
>> year(728647)
Undefined function 'year' for input arguments of type
'double'.
year requires an array of class datetime. It doesn't work on numeric arrays.
"In excel, the first day is the first of january 1900"
It's a bit more complicated. An excel date is the number of days since 0-Jan-1900, but excel incorrectly assumes that 1900 is a leap year, so you've got an extra day for all dates after 28-Feb-1900.
In any case, it's a bit irrelevant, matlab is perfectly capable of importing excel dates directly as datetime so you don't have to worry about any of this.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by