Time series data events

조회 수: 6 (최근 30일)
Ben Gibbingwork
Ben Gibbingwork 2021년 3월 4일
댓글: Ben Gibbingwork 2021년 3월 29일
Hola file exchange,
I have set of time series fiels for 6 locations. It is acceleration data from 6 sesnors deployed on machines. I also have a list of events in excel, in the structure in the image below. I want to mark the event on the time series plot, possibly with a line. How to plot the time series for each sensor and then only plot the events relating to that location - example - location number 1 has 2 events in the table below. So the time series plot should show these events.
Gracias todos

채택된 답변

Peter Perkins
Peter Perkins 2021년 3월 5일
편집: Peter Perkins 2021년 3월 5일
Ben, I'm not sure where you are starting from. I'm gonna show how to do this with timetables. Imagine you have a timetable containing data from three channels, sampled at 10Hz over 10 sec:
>> T = 10;
>> n = 100;
>> numChannels = 3;
>> X = cumsum(randn(n,numChannels));
>> tt = sortrows(array2timetable(X,"SampleRate",n/T));
tt =
8×3 timetable
Time X1 X2 X3
_______ ________ ________ _______
0 sec -0.33824 1.0395 0.94041
0.1 sec 0.19002 0.92269 1.2896
0.2 sec 1.2469 0.27439 3.1488
0.3 sec 1.2617 0.23641 4.0759
0.4 sec 2.8764 0.037084 2.849
0.5 sec 2.0606 0.91875 2.5217
0.6 sec 0.062812 0.86261 3.4134
0.7 sec -0.68538 0.021371 3.7015
[snip]
And imagine you have 8 events for those channels over that time range:
>> numEvents = 8;
>> events = timetable(seconds(sort(T*rand(numEvents,1))),randi(numChannels,numEvents,1),'VariableNames',"Channel")
events =
8×1 timetable
Time Channel
__________ _______
2.1327 sec 2
2.6871 sec 1
3.8015 sec 2
4.1693 sec 2
4.7535 sec 3
6.809 sec 2
7.7221 sec 3
9.8668 sec 2
The following code interpolates each channel at its event times and overlays that on a plot of the raw data:
for chnl = 1:numChannels
chnlEvents = retime(tt(:,chnl),events.Time(events.Channel == chnl),"linear");
subplot(3,1,chnl), plot(tt.Time,tt{:,chnl},'b-',chnlEvents.Time,chnlEvents{:,1},'r*','MarkerSize',10)
end
and results in a plot like this
The stackedplot function would be a fine way to plot the raw data on three axes, but that will not let you add the overlay. So the code above makes the three plots "by hand".
  댓글 수: 2
Adam Danz
Adam Danz 2021년 3월 5일
I agree with @Peter Perkins that this sounds like a job for stackedplot.
To add the vertical reference lines, you just need to specify the axis handles which can be done relatively easily using undocumented methods explained here in this answer.
Ben Gibbingwork
Ben Gibbingwork 2021년 3월 29일
Thank you for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series Events에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by