Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

addevent

Add event to timeseries object

Syntax

ts = addevent(ts,e)
ts = addevent(ts,Name,Time)

Description

ts = addevent(ts,e) adds one or more tsdata.event objects, e, to the timeseries object ts. e is either a single tsdata.event object or an array of tsdata.event objects.

ts = addevent(ts,Name,Time) constructs one or more tsdata.event objects and adds them to the Events property of ts. Name is a cell array of event name strings. Time is a cell array of event times.

Examples

Create a time-series object and add an event to this object.

%% Import the sample data
load count.dat

%% Create time-series object
count1=timeseries(count(:,1),1:24,'name', 'data');

%% Modify the time units to be 'hours' ('seconds' is default)
count1.TimeInfo.Units = 'hours';

%% Construct and add the first event at 8 AM
e1 = tsdata.event('AMCommute',8);

%% Specify the time units of the time
e1.Units = 'hours';

View the properties (EventData, Name, Time, Units, and StartDate) of the event object.

get(e1)

MATLAB® software responds with

    EventData: []
         Name: 'AMCommute'
         Time: 8
        Units: 'hours'
    StartDate: ''
%% Add the event to count1
count1 = addevent(count1,e1);

An alternative syntax for adding two events to the time series count1 is as follows:

count1 = addevent(count1,{'AMCommute' 'PMCommute'},{8 18})

Introduced before R2006a

Was this topic helpful?