Converting and plotting serial number to time format [hh:mm]

I have a data with client number and parking time for EV charging station.The data is loaded in xlsx format. Please find the below attached parking time data sample.
Parking time data sample:
7:05:55 AM
12:41:02 AM
12:38:50 AM
When i clear formats in excel , it becomes
0.295775463
0.02849537
0.026967593
When i use this data for plotting as bar graph (parking time against the cleint number)in matlab , it shows the serial number format.Below is the code i have used.Kindly help to make it appear in 24 hour time format (Parkingtime[hh:mm] in y axis.
z=xlsread('time.xlsx');
parkingtime=z((1:end),4);
clientnumber=z((1:end),1);
parkingtime = parkingtime.';
bar(clientnumber,parkingtime)

Respuestas (1)

Ideally, there should be a date as well.
In the interim:
t = [0.295775463
0.02849537
0.026967593];
DT1 = datetime(t, 'ConvertFrom','excel', 'Format','HH:mm')
produces:
DT1 =
3×1 datetime array
07:05
00:41
00:38
This converts the times appropriately. Make appropriate changes to the 'Format' property to get the result you want.
(The date values need to be supplied, since I seriously doubt there were abundant EV charging stations in 1899.)

4 comentarios

The timeofday function will likely be of use here as well as will basic datetime arithmetic (if you record the timestamps of when vehicles arrive.)
t = [0.295775463
0.02849537
0.026967593];
DT1 = datetime(t, 'ConvertFrom','excel', 'Format','HH:mm')
DT1 = 3×1 datetime array
07:05 00:41 00:38
TOD = timeofday(DT1)
TOD = 3×1 duration array
07:05:55 00:41:01 00:38:50
% Modifying the data so the first car arrived at 7 AM today, the second around
% midnight tomorrow, and the third around midnight the day after tomorrow
DT2 = DT1 + days([0; 1; 2]);
howlong = diff(DT2)
howlong = 2×1 duration array
17:35:06 23:57:48
howlong2 = DT2(2:end)-DT2(1:end-1)
howlong2 = 2×1 duration array
17:35:06 23:57:48
Steven Lord — Thank you!
NN
NN el 22 de Nov. de 2020
thank you
My (our) pleasure!
If my Answer helped you solve your problem, please Accept it!
.

Iniciar sesión para comentar.

Categorías

Preguntada:

NN
el 22 de Nov. de 2020

Comentada:

el 22 de Nov. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by