convert epoch time to yyyyMMDDHHMMSS
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to plot sensor data from csv file (between rows 150 and 220) using this code:
clear
close all
file_name = 'HPP2.csv'
% read the numerical data:
A = csvread(file_name,2,1);
% read the timing of each data set:
[sum,text,RAW] = xlsread(file_name,'A:A');
% Transform the calendar time into epoch time:
for uu = 2:(size(A,1)+1)
line = text{uu};
time_axis(uu-1) = cdflib.computeEpoch([str2num(line(1:4)) str2num(line(6:7)) str2num(line(9:10)) str2num(line(12:13)) str2num(line(15:16)) str2num(line(18:19)) 0]);
end
start=150
last=220
x=time_axis(start:last);
y1 = A(start:last,80);
y2 = A(start:last,58);
Y3=A(start:last,55)
% Top two plots
tiledlayout(2,2)
nexttile
plot(x,y1)
xlabel('epoch_time')
ylabel('mass')
nexttile
plot(x,y2)
xlabel('epoch_time')
ylabel('temperature')
My problem is that I want to display the actual time/date on the x axis instead of the epoch time? I know the actual time/date correspond to rows 150 and 220?
how can I make convert epoch time back to real time/date format please?
0 comentarios
Respuestas (3)
Cris LaPierre
el 17 de Oct. de 2020
% Example: Return the number of days since January 1, 2000.
T = datetime(X,'ConvertFrom','epochtime','Epoch','2000-01-01')
% Example: Return the number of days since January 1, 2000, where X represents the time in milliseconds since or before that date.
T = datetime(X,'ConvertFrom','epochtime','Epoch','2000-01-01','TicksPerSecond',1000)
2 comentarios
Cris LaPierre
el 17 de Oct. de 2020
If you load the data as datetime, then plotting is as easy as plot(x,y). You do not need to do anything special. If you want to modify the format so something specific, you can use xtickformat.
Without having access to your data, we can only speak about hypotheticals, though. Consider attaching your data to your post for more specific advice. Use the paperclip icon.
Cris LaPierre
el 18 de Oct. de 2020
Just as an example, here is one way to read it in.
opts = detectImportOptions("HPP2.xlsx");
% Keep variable names as they are
opts.VariableNamingRule = "preserve";
% Set options to corretly read time: 2020-06-24T11:19:01Z
opts = setvartype(opts,"time","datetime");
opts = setvaropts(opts,"time","InputFormat",'yyyy-MM-dd''T''HH:mm:ss''Z');
% Manually select columns to import
opts.SelectedVariableNames = [1,6,18,32,35,38:41,43:45,47,56,58,59,78,81];
% Load data as a timetable
data = readtimetable("HPP2.xlsx",opts);
% Set display format of time
data.time.Format = 'ddMMMyy HH:mm:ss'
0 comentarios
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!