Excel sheet time data defaulting to January 1st, 1970 on plot
조회 수: 9 (최근 30일)
이전 댓글 표시
I am importing excel sheeting to MatLab with time (MM-dd-yyyy HH-mm) in the first column and voltage data in the second column. When I go to plot this data, the x-axis (time) defaults to January 1st, 1970. How do I go about fixing this? The date my excel data starts on is December 1st, 2021.
I have been using the datetime function but think it may need to be tweaked.
댓글 수: 1
Steven Lord
2022년 1월 11일
Please show us how you imported the data from the spreadsheet and how you used datetime as part of the process of preparing your data. Did you use readtable on your spreadsheet? If not did you use datetime to 'ConvertFrom', 'Excel' the data you read from the file?
채택된 답변
Star Strider
2022년 1월 11일
My best guess is that datetime is not interpreting the time column correctly.
It would need to be something like this:
time = '12-01-2021 00-01'
dttime = datetime (time, 'InputFormat','MM-dd-yyyy HH-mm', 'Format','yyyy/MM/dd HH:mm')
Use the appropriate string for the 'Format' name-value pair depending on how the result is to be displayed.
.
댓글 수: 3
Star Strider
2022년 1월 11일
I would use ‘logical indexing’ to eliminate the 1970 values —
time = ['12/20/2021 13:10:00'
'12/20/2021 13:10:01'
'12/20/2021 13:10:02'
'01/11/1970 15:40:00'
'12/20/2021 13:10:03'];
dt_time = datetime(time, 'InputFormat','MM/dd/yyyy HH:mm:ss')
year_not_1970 = year(dt_time) ~= 1970;
dt_time_new = dt_time(year_not_1970)
Using this in a table would require a second dimension reference —
T = table(dt_time, randn(size(dt_time)))
T_new = T(year_not_1970,:)
or something similar.
.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!