how to solve date serial number contains gap?
4 views (last 30 days)
Show older comments
I have more than 100000 dates and time data in one column [VariableA].I already convert it to serial date numbers by using datenum([VariableA]).However, there is the gap between the date. Its skip one month for example 1 January 1975,1 February 1975,1 March 1975.... It seems Matlab read as mm/dd/yy..but when I change my data as this format, there is an error. Please help me to solve this problem. Thank you for your help.
3 Comments
Answers (1)
Rik
on 29 Aug 2017
If you have trouble with a function, you should have a look at the documentation (type doc datenum or Google it). If you would have taken a look at it, you might have noticed you can put in a formatIn variable. The formatting of this string can be a bit tricky, so look very carefully if you have followed EXACTLY what the list is showing (and post an update here if you still have trouble getting it right).
%assuming a format like '1 February 1975 10:50 AM'
DateString='1 February 1975 10:50 AM';
formatIn = 'dd mmmm yyyy HH:MM PM';
serial_date=datenum(DateString,formatIn);
%see it is correct:
disp(datetime(serial_date,'ConvertFrom','datenum'))
It is also a good idea to answer the question KL posted in his comment, as the documentation notes: "The best way to represent points in time is by using the datetime data type. The best way to represent elapsed time is by using the duration or calendarDuration data types." These data types may not be available on your release (they were introduced in R2014b).
0 Comments
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!