필터 지우기
필터 지우기

converting a date into a num

조회 수: 3 (최근 30일)
Aleksandra Ksiezyk
Aleksandra Ksiezyk 2021년 12월 12일
답변: Star Strider 2021년 12월 12일
I have a structure with 2 columns. When i click on a struction icon i see my dates (Time): dd-mmm-yyy HH:MM:SS (like in a pic above: 01-Jan-2016 00:00:00 ). When i click my dates (Time) of the same structure from the Workspace i get results already converted into a num (doubble). The problem is when i type str(myStructure.Time) i am getting: '08-Apr-2685' (This is the last value). has anyone an idea why is that ?

답변 (2개)

KSSV
KSSV 2021년 12월 12일
You can convert dates which are in datetime class using the function datenum.

Star Strider
Star Strider 2021년 12월 12일
I have no idea what those date numbers are, since they are not MATLAB date numbers, and attempting to convert them as 'excel' or 'posix' fails completely.
Try using a bit of linear algebra to convert them to MATLAB datenum numbers, then convert them to datetime arrays —
dn = datenum([2015 12 31 22 30 00; 2015 12 31 22 40 00]); % Necessary
B = [[63067800; 63068400] ones(2,1)] \ dn; % Necessary (Mapping Vector)
PivotYear = datetime(B(2), 'ConvertFrom','datenum') % Simply Out Of Curiosity
PivotYear = datetime
31-Dec-2013 23:39:59
dnv = datetime([[63067800; 63068400; 63069000; 63069600; 63070200; 63070800; 63071400; 63072000] ones(8,1)] * B, 'ConvertFrom','datenum')
dnv = 8×1 datetime array
31-Dec-2015 22:30:00 31-Dec-2015 22:40:00 31-Dec-2015 22:50:00 31-Dec-2015 23:00:00 31-Dec-2015 23:10:00 31-Dec-2015 23:20:00 31-Dec-2015 23:30:00 31-Dec-2015 23:40:00
Copying them from the Command Window — or better yet, saving them to a variable as a column vector — and then using this approach will likely convert all of them successfully. (It would be nice to know what they are and how to convert them if the encoding is known.)
.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by