Plot HH:MM on x-axis with time data imported from excel

4 visualizzazioni (ultimi 30 giorni)
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
Guillaume il 26 Feb 2020
I should have ask that initially as well, can you attach a sample xls file?
Patrick Bonzi
Patrick Bonzi il 26 Feb 2020
In fact since I have always the same timestep and the beginning and end of the days are also always the same I created the time vector as 'x'.
Anyway, in the xls file the first columns is the date and time as recorded by the device, the second column is the time I entered manually because I couldn't use/import the values from the 1st column with Matlab.
Thanks,
Patrick

Accedi per commentare.

Risposte (1)

Guillaume
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
Patrick Bonzi
Patrick Bonzi il 28 Feb 2020
What if I want to have several days (5 days from 13.01.2020 to 17.01.2020) on the x-axis each day starting at 9:00 AM and ending at 4:50 PM without interruptions between 4:50 PM to 9:00 AM of the next day?
Thanks,
Patrick
ADJE JEREMIE ALAGBE
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?

Accedi per commentare.

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!

Translated by