How can I achieve similar functionality to the "time2num" function without using the Predictive Maintenance Toolbox in MATLAB R2024b?
조회 수: 6 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2025년 12월 16일 0:00
답변: MathWorks Support Team
2025년 12월 23일 21:46
I am working with datetime arrays that I would like to convert to numeric vectors. In particular, each element of the numeric vector should indicate the number of days that have elapsed between the corresponding datetime array element and the first datetime array element.
I saw that the "time2num" function can implement this workflow easily. However, I don't have access to the Predictive Maintenance Toolbox.
Are there any ways I can achieve a similar workflow without the "time2num" function?
채택된 답변
MathWorks Support Team
2025년 12월 16일 0:00
It is possible to replicate the behavior of "time2num" using the "convertTo" function, which can also be used to convert datetime arrays into numeric vectors, and does not require additional toolboxes. The following code snippet shows how the "convertTo" function can be used to achieve the same result as the "time2num" function:
T = [datetime('yesterday'), datetime('today'), datetime('tomorrow')]
disp(time2num(T, 'days'))
disp(convertTo(T, 'epochtime', 'Epoch', datetime('yesterday')) / 86400) % 86400 seconds in a day
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!