Timeseries using startdate - plot with events

Hi, I have some difficulties displaying correctly timeseries with events in a plot with Matlab r2016b). In my case, I have a same startdate defined for my timeserie and all the events. When I plot the timeseries, the datatip for the second (and following) event displays the information of the first one.Hereafter is a simple example reproducing my issue:
test1 = timeseries();
test1.Time = [1 2 3 4 5];
test1.TimeInfo.Format= 'yyyy-mm-dd HH:MM:SS.FFF';
test1.TimeInfo.Units = 'seconds';
test1.TimeInfo.StartDate= '2018-01-01 00:00:00.000';
test1.Data = [2 1 4 1 4]';
event1 = tsdata.event('event1',2.0001);
event1.StartDate= '2018-01-01 00:00:00.000';
event2 = tsdata.event('event2', 3.45001);
event2.StartDate= '2018-01-01 00:00:00.000';
test1 = test1.addevent(event1);
test1 = test1.addevent(event2);
figure
subplot(1,1,1)
plot(test1)
What can I do to have a correct display of my events?

1 Commento

I don't have this issue with Matlab r2016a. But I have another one when I combine time series with and without event in a plot. If the last time serie is without event, the events data from the first time serie are not displayed correctly :
test1 = timeseries();
test1.Time = [1 2 3 4 5];
test1.TimeInfo.Format= 'yyyy-mm-dd HH:MM:SS.FFF';
test1.TimeInfo.Units = 'seconds';
test1.TimeInfo.StartDate= '2018-01-01 00:00:00.000';
test1.Data = [2 1 4 1 4]';
event1 = tsdata.event('event1',2.0001);
event1.StartDate= '2018-01-01 00:00:00.000';
event2 = tsdata.event('event2', 3.45001);
event2.StartDate= '2018-01-01 00:00:00.000';
test1 = test1.addevent(event1);
test1 = test1.addevent(event2);
test2 = timeseries();
test2.Time = [1 2 3 4 5];
test2.TimeInfo.Format= 'yyyy-mm-dd HH:MM:SS.FFF';
test2.TimeInfo.Units = 'seconds';
test2.TimeInfo.StartDate= '2018-01-01 00:00:00.000';
test2.Data = [5 5 5 5 5]';
figure(2)
subplot(1,1,1)
plot(test1)
hold on
plot(test2)
hold off

Accedi per commentare.

Risposte (1)

Try to use the following format to define the StartDate:
test1.TimeInfo.StartDate= datenum(2018,01,01,0,0,0);
event2.StartDate= datestr(datenum(2018,01,01,0,0,0)));

Prodotti

Richiesto:

il 1 Gen 2018

Risposto:

il 5 Ott 2018

Community Treasure Hunt

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

Start Hunting!

Translated by