From: bjornnak on 7 May 2010 10:16 Hi, I'm a new user of Matlab, so I guess this one should be pretty easy. I have a dated time-series (yyyy-mm-dd) and I want to convert the dates to Matlab serial dates. time = datenum(dates,'yyyy-mm-dd') This doesn't seem to work, and I get different errors when I try to tweak the command and inputs. First, the dates are in a cell array (icon with { } brackets), and it seems Matlab prefers it in string (char) format, but I'm not too sure about this. I have no problem getting a single date, using datenum(dates{1}) but when I try to more than one date it tells me Index exceeds matrix dimensions. The array is 10183x1, so shouldn't the proper input be datenum(dates{:, 1}) [this means, get the entire column 1, right?) I want the results to end up in the 'time' vector, and I've tried different things to solve to matrix dimension issue: 1. creating an empty 10183x1 vector, 2. creating a completely empty 'time' vector, and 3. defining it when running the datenum command, as in row 3 of this post. Nothing works. If the issue lies in that my dates are in a cell array rather than in a char, I'm having problems here to since I cannot find a way that simply lets me convert the array to char. Any help is very welcolme! / Björn
From: us on 7 May 2010 15:41 bjornnak <bjorn.r.jonsson(a)gmail.com> wrote in message <8134dbc3-b6b9-4e95-b327-3e02332ab7de(a)k29g2000yqh.googlegroups.com>... > Hi, > > I'm a new user of Matlab, so I guess this one should be pretty easy. > > I have a dated time-series (yyyy-mm-dd) and I want to convert the > dates to Matlab serial dates. > > time = datenum(dates,'yyyy-mm-dd') > > This doesn't seem to work, and I get different errors when I try to > tweak the command and inputs. > > First, the dates are in a cell array (icon with { } brackets), and it > seems Matlab prefers it in string (char) format, but I'm not too sure > about this. > > I have no problem getting a single date, using datenum(dates{1}) but > when I try to more than one date it tells me Index exceeds matrix > dimensions. > > The array is 10183x1, so shouldn't the proper input be datenum(dates{:, > 1}) [this means, get the entire column 1, right?) > > I want the results to end up in the 'time' vector, and I've tried > different things to solve to matrix dimension issue: 1. creating an > empty 10183x1 vector, 2. creating a completely empty 'time' vector, > and 3. defining it when running the datenum command, as in row 3 of > this post. Nothing works. > > If the issue lies in that my dates are in a cell array rather than in > a char, I'm having problems here to since I cannot find a way that > simply lets me convert the array to char. > > Any help is very welcolme! > > / Björn one of the solutions d={ % <- a CELL of CHAR strings... '2000-01-01' '2001-02-02' '2010-12-31' }; dt=datenum(d,'yyyy-mm-dd') %{ % dt = 730486 730884 734503 %} % check datestr(dt) %{ 01-Jan-2000 02-Feb-2001 31-Dec-2010 %} us
|
Pages: 1 Prev: matlab precision determinant problem Next: Steady State with SimBiology |