Plot HH:MM on x-axis with time data imported from excel
이전 댓글 표시
Hi everyone,
I have tried several times and looked up in the questions but still can't find a solution that works for me.
I have time data in excel from 9:00 to 16:50 with time step of 5 minutes (9:00, 9:05, 9:10,...16:50) I want to have the time on the x-axis of my plots in the HH:MM format. When I import the time values in Matlab with xlsread the time is converted to decimal numbers. If i plot them directly I have decimal numbers on the x-axis so I tried datenum, datestr etc but nothing worked so far. In addition, I would like to select specific ticks to appear on the x-axis (9:00, 10:00, 11:30, 13:00, 14:30, 16:50).
Any help is appreciated, I have my master thesis to handle in in a few weeks and I want the plots to be perfect :D
Patrick
댓글 수: 4
Patrick Bonzi
2020년 2월 26일
Guillaume
2020년 2월 26일
I should have ask that initially as well, can you attach a sample xls file?
Patrick Bonzi
2020년 2월 26일
답변 (1개)
Guillaume
2020년 2월 26일
I was asking for an example of the original file in order to show you how to import it properly.
Anyway, a variation of this should work:
data = readtable('yourexcelfile.xlsx'); %readtable is much better than xlsread
data.DateTime_GMT_01_00 = datetime(data.DateTime_GMT_01_00, 'InputFormat', 'MM/dd/yy hh:mm:ss a');
plot(data.DateTime_GMT_01_00, data.nameof2ndvariable);
xtickformat('hh:mm a'); %Note that 'HH:MM PM' is not a valid format
댓글 수: 3
Patrick Bonzi
2020년 2월 26일
Patrick Bonzi
2020년 2월 28일
ADJE JEREMIE ALAGBE
2020년 12월 4일
Hi, I tried this on my data, but it says "Error using datetime (line 589). Numeric input data must be a matrix with three or six columns, or else three, six, ..."
Could you please tell me what is not correct with my data or input?
카테고리
도움말 센터 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!