Plot HH:MM on x-axis with time data imported from excel
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Guillaume
il 26 Feb 2020
I should have ask that initially as well, can you attach a sample xls file?
Risposte (1)
Guillaume
il 26 Feb 2020
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 Commenti
ADJE JEREMIE ALAGBE
il 4 Dic 2020
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?
Vedere anche
Categorie
Scopri di più su Data Import from MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!