Converting and plotting serial number to time format [hh:mm]
Mostrar comentarios más antiguos
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)
Star Strider
el 22 de Nov. de 2020
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')
TOD = timeofday(DT1)
% 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)
howlong2 = DT2(2:end)-DT2(1:end-1)
Star Strider
el 22 de Nov. de 2020
Steven Lord — Thank you!
NN
el 22 de Nov. de 2020
Star Strider
el 22 de Nov. de 2020
My (our) pleasure!
If my Answer helped you solve your problem, please Accept it!
.
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!