year function does not read properly
조회 수: 4 (최근 30일)
이전 댓글 표시
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
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
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
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 Center 및 File Exchange에서 Calendar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!