Converting Matlab time vector into fractional year date

I feel ridiculous asking this, but is there a single function in Matlab that takes a series of integers/vectors (e.g. [2012,1,1,10,30,03]) or a Matlab time number (e.g. 735630) and converts it into a usable and plottable date of form 2012.01231 in one step? Thanks!

Answers (1)

What do you mean by plotable ?
There are many functions related to dates
doc datenum
doc datevec
doc datestr

9 Comments

Thanks, Azzi. I know those functions well. Basically I'd like to be able to convert various date formats (like those I mention above) to an integer i.e. 2013.2031, which is stored as a double, or vector, or matrix. Does that make sense? I.e. I have data that I'd like to be able to plot against time without having to have the Matlab date format as units on the X axis. Maybe I'll just have to write one myself, but I'd prefer to not have to deal with the issue of accounting for leap years.
What is the problem with datenum ?
2013.2031 (I'm using this just as an example--I haven't calculated it) would represent date as the year 2013 plus the fraction of the year that has passed by a given date, say March 20th at 02:30:05. Datenum gives the Matlab date, which isn't that useful for me if I want to plot a time series between 2012 and 2014 where the x axis is time. I.e. if I said n = datenum(2001,12,19), n=731204. But I'd prefer to have that as an integer of form 2001.95 (or whatever it is)
n=731204 is an integer, while 2001.95 is not an integer, can you explain what you want ?
So sorry. I've been blundering on with the term integer, when I mean "real number".
Now can you explain what this real number represent ?
For example if
d='07-Feb-2014 23:39:42'
Maybe OP would want something like this (with modifications to make it generic):
2014+(datenum(d) - datenum('1-jan-2014'))/(datenum('1-jan-2015') - datenum('1-jan-2014'))
What about time between 0 and 1?
date1='01-01-2000'
date2='01-01-2001'
dat=datenum(date1,'dd-mm-yyyy'):datenum(date2,'dd-mm-yyyy')
out=mat2gray(dat)

Sign in to comment.

Asked:

on 7 Feb 2014

Commented:

on 7 Feb 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!