day and month inverted in the time scaling
조회 수: 2 (최근 30일)
이전 댓글 표시
time x array : 04/05/2023 00:00:22.384 04/05/2023 00:00:59.361 04/05/2023 00:02:33.408
When using stairs function the legend in x is displayed Apr 05, 2023 where it should be May 04, 2023.
How can I set the time display?
댓글 수: 0
채택된 답변
Dyuman Joshi
2023년 9월 26일
Extract the day and month from the datetime values and swap them.
%Example
in = [datetime(2023,4,5,00,00,22.384) datetime(2023,4,5,00,00,59.361) datetime(2023,4,5,00,02,33.408)]
%Get year month and day
[y,m,d] = ymd(in)
%Get hour minute and second
[H,M,S] = hms(in);
out = datetime(y,d,m,H,M,S)
댓글 수: 3
추가 답변 (1개)
Les Beckham
2023년 9월 26일
편집: Les Beckham
2023년 9월 26일
If you created your "time x array" by reading strings from a text file, for example, you need to specify the 'InputFormat' argument when you read the strings using the datetime function (see documentation here).
date_strings = ["04/05/2023 00:00:22.384", "04/05/2023 00:00:59.361", "04/05/2023 00:02:33.408"];
time_x_array = datetime(date_strings, 'InputFormat', 'dd/MM/yyyy hh:mm:ss.SSS')
댓글 수: 2
Steven Lord
2023년 9월 26일
Note that if you don't include the InputFormat, MATLAB will warn you that your text data is ambiguous. It can't tell whether the month or the date is first. It will even suggest the alternate format that also matches the text representation.
date_strings = ["04/05/2023 00:00:22.384", "04/05/2023 00:00:59.361", "04/05/2023 00:02:33.408"];
time_x_array = datetime(date_strings)%, 'InputFormat', 'dd/MM/yyyy hh:mm:ss.SSS')
While MATLAB Answers runs the most recent release of MATLAB, I confirmed that this warning appears in release R2021b as well.
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!