How to add datetime from seconds?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hanif hamden
el 29 de Mayo de 2019
Comentada: hanif hamden
el 13 de Jun. de 2019
I have txt file as attached.
I have initial date time on the first row.. How i want to add this datetime with seconds for each row from first column?
This is example of my coding:
%% Input data
A = dlmread('ex1.txt');
% Identify year, month, day, hour, minute, second [Y,M,D,H,Mn,S]
Y = A(1,1); M = A(1,2); D = A(1,3); H = A(1,4); Mn = A(1,5); S = A(1,6);
dt = datetime(Y,M,D,H,Mn,S)
% Identify parameter after 2nd Row
Ts = seconds(A(2:end,1)); lat = A(2:end,2); lon = A(2:end,3); h = A(2:end,4);
dt.Second = dt.Second + Ts
When I run, the error showed like this:
Error using Test (line 12)
Numeric input data must be real.
0 comentarios
Respuesta aceptada
Peter Perkins
el 4 de Jun. de 2019
That's not the error that I get, but it's possible that you are using an older version with different error handling.
In any case: The .Seconds property of a datetime, like all six of the time component properties, is a raw numeric value (it's the .Second property after all, there'd be no point in it having units). You are trying to add a duration to it. You want to either do this:
dt.Second = dt.Second + A(2:end,1)
or (better) this:
dt = dt + seconds(A(2:end,1))
Más respuestas (0)
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!