Thread Subject: Creating Timeseries of my data

Subject: Creating Timeseries of my data

From: Michal M

Date: 15 Nov, 2009 10:25:03

Message: 1 of 6

Hi,
Can anyone help me - how do I get matlab to recognize my data as timeseries data?
I have matrix A -
A(1, : ) -- A(21, :) - my data, collected at half hour interval
A(22, :) - the year
A(23, :) - month
row 24 - day of month
row 25 - hour of day
row 26 - day of week
row 27 - day of year

I have added the last rows with a home made function that adds a time axis to the data.
But now I want to plot the data against a time line. How do I tell matlab to recognize it as time series?
I have understood how to create a time series object, but not how to tell it that the units are half hour intervals, not seconds 0 - N-1.
Thanks

Subject: Creating Timeseries of my data

From: Bastian

Date: 16 Nov, 2009 17:14:02

Message: 2 of 6

"Michal M" <landaumichal@hotmail.com> wrote in message <hdoktv$2b7$1@fred.mathworks.com>...
> Hi,
> Can anyone help me - how do I get matlab to recognize my data as timeseries data?
> I have matrix A -
> A(1, : ) -- A(21, :) - my data, collected at half hour interval
> A(22, :) - the year
> A(23, :) - month
> row 24 - day of month
> row 25 - hour of day
> row 26 - day of week
> row 27 - day of year
>
> I have added the last rows with a home made function that adds a time axis to the data.
> But now I want to plot the data against a time line. How do I tell matlab to recognize it as time series?
> I have understood how to create a time series object, but not how to tell it that the units are half hour intervals, not seconds 0 - N-1.
> Thanks

Could you please provide an actual example of your data matrix. It is not clear what you matrix looks like.

Subject: Creating Timeseries of my data

From: TideMan

Date: 16 Nov, 2009 18:52:49

Message: 3 of 6

On Nov 15, 11:25 pm, "Michal M" <landaumic...@hotmail.com> wrote:
> Hi,
> Can anyone help me - how do I get matlab to recognize my data as timeseries data?
> I have matrix A -
> A(1, : )  -- A(21, :) - my data, collected at half hour interval
> A(22, :) - the year
> A(23, :) - month
> row 24 - day of month
> row 25 - hour of day
> row 26 - day of week
> row 27 - day of year
>
> I have added the last rows with a home made function that adds a time axis to the data.
> But now I want to plot the data against a time line. How do I tell matlab to recognize it as time series?
> I have understood how to create a time series object, but not  how to tell it that the units are half hour intervals, not seconds 0 - N-1.
> Thanks

You need to convert to Matlab days.
Here's one way:
t=datenum(A(22,:),A(23,:),A(24,:)) + A(25,:)/24;
Now, you can plot using t as the abscissa and use function datetick to
label the axis.

Subject: Creating Timeseries of my data

From: Michal M

Date: 17 Nov, 2009 09:31:03

Message: 4 of 6

Here is a sample column, with explanation of each row:

first rows, data.
  1.0e+003 *

    0.0160 0.0140
    0.0890 0.0080
    0.0006 0.0004
    0.0205 0.0208
    0.0206 0.0540
       NaN NaN
    0.0330 0.1000
    0.0030 0.0350
    0.0290 0.0460
    0.0350 0.0510
    0.0060 0.0130
    0.0260 0.0300
         0 0.0010
         0 0
         0 0
    0.0039 0.0051
         0 0
    0.0008 0.0024
         0 0
    0.0180 0.0200
       NaN NaN
    2.0050 2.0050
    0.0010 0.0010
    0.0010 0.0010
    0.0100 0.0105
    0.0070 0.0070
         0 0
    0.0010 0.0010

last 7 rows - time series information.
    1.0e+003 *
    2.0050 year
    0.0010 month
    0.0010 day of month
    0.0100 hour of day
    0.0070 day of week
         0 is holiday? if == 0 it is not a holiday
    0.0010 day in year

Thanks!
"Bastian " <bastianschmidt@trentu.removethistext.ca> wrote in message <hds18q$48h$1@fred.mathworks.com>...
> "Michal M" <landaumichal@hotmail.com> wrote in message <hdoktv$2b7$1@fred.mathworks.com>...
> > Hi,
> > Can anyone help me - how do I get matlab to recognize my data as timeseries data?
> > I have matrix A -
> > A(1, : ) -- A(21, :) - my data, collected at half hour interval
> > A(22, :) - the year
> > A(23, :) - month
> > row 24 - day of month
> > row 25 - hour of day
> > row 26 - day of week
> > row 27 - day of year
> >
> > I have added the last rows with a home made function that adds a time axis to the data.
> > But now I want to plot the data against a time line. How do I tell matlab to recognize it as time series?
> > I have understood how to create a time series object, but not how to tell it that the units are half hour intervals, not seconds 0 - N-1.
> > Thanks
>
> Could you please provide an actual example of your data matrix. It is not clear what you matrix looks like.

Subject: Creating Timeseries of my data

From: Bastian

Date: 18 Nov, 2009 17:37:04

Message: 5 of 6

Hi,

I think I interpreted your data correctly...
Since there are only 21 records in your data set I will outline a manual method of creatign the timeseries, which should get you started. With some more effort you can create an automated means for generatign your date strings.

So, you can use the MATLAB timeseries function:
ts = timeseries(Data,Time)

Place all your data (21 rows by 2 columns) in a matrix. This matrix will be the "Data" input argument of the function above:

Ex.
MyData = [16 14; 89 8; 0.6 0.4]

Create a new "Time" input by creating a string array of your 21 times in the following format mm/dd/yy HH:MM:SS using your half hour time step.
For Example:

Ex.
MyTimes = {'01/25/2009 18:30:00';'01/25/2009 19:00:00';'01/25/2009 19:30:00'};

To summarize the code to create and plot:

MyData = [16 14; 89 8; 0.6 0.4;];
MyTimes = {'01/25/2009 18:30:00';'01/25/2009 19:00:00';'01/25/2009 19:30:00'};
ts = timeseries(MyData,MyTimes);
plot(ts)
set(gca,'XTickLabel',cellstr(datestr(getabstime(ts),'HH:MM')),'XTickMode','manual','Tick',ts.time)

The timeseries function creates (using these two inputs) a new time series object with a 30 minute time increment. You can view the timeseries using the Workspace Browser.

When you plot the time series it will automatically use your times as tics on the x-axis.

You can also use the many other timerseries specific functions/tools available in MATLAB (eg. getabstime, tstool etc.).

Hope that helps.

Subject: Creating Timeseries of my data

From: Bastian

Date: 18 Nov, 2009 17:43:04

Message: 6 of 6

My apologies. The last line of the sample code above should read:

set(gca,'XTickLabel',cellstr(datestr(getabstime(ts),'HH:MM')),'XTickMode','manual','XTick',ts.time)

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
timeseries Michal M 15 Nov, 2009 05:29:04
rssFeed for this Thread

Contact us at files@mathworks.com