how to use datestr?
Mostrar comentarios más antiguos
Dear all, I tried to convert the matlab serial dates (vector) back to a date string 'yyy-MM-dd-HH-mm using the following command. I use matlab2013a. time_num is a vector of serial dates. I have attached the file please.
time_format=datestr(datetime(time_num/1440,'ConvertFrom','datenum','Format','yyyy-MM-dd HH:mm')); %saves new time in date format
Undefined function 'datetime' for input arguments of type 'double'.
Respuesta aceptada
Más respuestas (2)
The serial date numbers in your time_num.mat file can be converted into strings like this:
>> datestr(time_num(1:10), 'yyyy-mm-dd HH:MM')
ans =
2013-12-20 00:00
2013-12-20 00:10
2013-12-20 00:20
2013-12-20 00:30
2013-12-20 00:40
2013-12-20 00:50
2013-12-20 01:00
2013-12-20 01:10
2013-12-20 01:20
2013-12-20 01:30
Read the datestr documentation to know how this works, and also to pick the correct output format string.
Rajesh PolamReddy
el 7 de Ag. de 2018
I need to convert the vector Tstamp to HH:MM:SS format
datestr is converting the vector to time of string but i don't see the converted data is correct
eg : Tstamp = [4696.9,4702.9,4708.9];
datestr(x,'HH:MM:SS PM')
I got answer as below
9:36:00 PM
9:36:00 PM
9:36:00 PM
If we see the Tstamp (1) i.e 4696.9 sec is not equal to 9:36:00 PM
Can any one help me ? Iam i missing something?
1 comentario
"If we see the Tstamp (1) i.e 4696.9 sec is not equal to 9:36:00 PM"
Actually it is a correct conversion, assuming that the input is a serial date number:
>> T = [4696.9,4702.9,4708.9];
>> datevec(T(:))
ans =
12 11 8 21 36 0
12 11 14 21 36 0
12 11 20 21 36 0
(but note that your values are not serial date numbers: this is your mistake).
"Can any one help me ?"
The MATLAB documentation can help you: "...represents each point in time as the number of days from January 0, 0000. The numeric values also can represent elapsed time in units of days"
"Iam i missing something?"
You assumed that MATLAB serial date numbers are seconds from some epoch, whereas in fact the documentation clearly describes them as being days from the 0th of January in year 0. The datestr documentation clearly describes its input as being a DateVector or DateNumber (what you used, and is measured in days).
You could either:
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!