Question on datestr to datetime conversion
이전 댓글 표시
Hi everyone, I'm working on a code that is a few years old and not originally made by me. Untill now I used matlab only for specific operation with matrices so I'm sorry if the question appear to be dumb.
First thing I did was to look at all warnings and tried to correct the code to not get them. Now the only one I still need to change is the use of datestr that since then it's become a discouraged instances.
Now I know that we can change:
datestr(t)
with
d = datetime(t)
d = string(d)
or even in a more compact way:
datestr(now)
with
char(datetime)
Now what I have in my code is something like this:
datestr(timeseries(i),formatOut)
and looking at the documentation of both functions I'm not sure on how to change it mantaining the expected output. If possible I would want to change only the datestr lines and I need to be sure that the result is exactly the same and not similar.
If anyone could help thank you very much :)
채택된 답변
추가 답변 (1개)
Peter Perkins
2023년 6월 5일
It's hard to tell what this code is doing, but while replacing this
datestr(now)
with this
char(datetime)
is a literal old to new translation, but it may not be what's really needed. The old datestr/datenum/datevec stuff required a lot of converting between representations to variously do arithmetic, calendar arithmetic, and readable output. datetime is intended to mostly avoid those kind of conversions: it's displays in whatever format you want, supports exact-time arithmetic with durations, and supports calendar arithmetic with calendarDuration.
So you may consider doing a less literal translation, and look at your code more conceptually.
Also: "... a custom function we made that create a table with real world data and the date associated with it." Dunno know what that means, but I'm guessing you should look at timetables.
카테고리
도움말 센터 및 File Exchange에서 Time Series Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!