Check if datetime is within a time interval and add to sequence accordingly?

조회 수: 5 (최근 30일)
EDIT: I'm now looking at the isbetween function in MATLAB
___________________
Hi all,
I'm a bit stuck on trying to build a sequence of events based on a truncated interval.
I have a vector, t3, containing datetimes and a vector, flags, containing sequence identifiers (1 for system up and 2 for down). I also have a vector, tInts, of datetimes for 5 minute intervals that span the entirety of t3.
So, for example, I have:
'2019-01-24 16:00:00'
'2019-01-24 16:00:04'
'2019-01-24 16:02:02'
'2019-01-24 16:03:36'
'2019-01-24 16:05:44'
'2019-01-24 16:06:12'
'2019-01-24 16:08:12'
'2019-01-24 16:09:13'
'2019-01-24 16:14:04'
'2019-01-24 16:14:35'
for t3,
flags = [2;1;2;1;2;1;2;1;2;1];
and tInts would be
'2019-01-24 16:00:00'
'2019-01-24 16:05:00'
'2019-01-24 16:10:00'
'2019-01-24 16:15:00'
I want to check that the values of t3 are within the 5 minute intervals in tInts, and, if they roll over, I want to insert an additional flag into a sequence. So, based on my example, at index 5 for t3, we exceed 5 minutes. The flags to that point are [2;1;2;1;2]; Now, I want to add an additional 1 (since it rolled over the 5 minutes in state 1) before the last 2, making
seq = [2;1;2;1;1;2]
and on and on through all of t3.
So I have a thought to try an if-statement inside a for-loop where I have some condition that would look at a certain t3 element and check if the difference from tInts(j) - t3(1) >= 0 then seq = [flags upto i; flags(i-1)] else seq = flags up to i.
I'm not really sure. Any help would be great.
Thanks,
E

채택된 답변

Erin Winkler
Erin Winkler 2019년 2월 6일
Hi all,
I actually figured it out on my own. For anyone who needs it in the future (I was using it for building a sequence for a Transition Matrix for a Markoc Chain), here's how I did it:
seq = [];
for i = 1:length(tInts)-1
tf = isbetween(t3,tInts(i),tInts(i+1));
indxF = find(tf,1,'first');
indxL = find(tf,1,'last');
seq = [seq; flags(indxF:indxL); flags(indxL)];
end

추가 답변 (1개)

Abhishek Kumar Tiwari
Abhishek Kumar Tiwari 2019년 12월 23일
Hi guys, I am working on my thesis and need some help.
In my project,
x=1:number_of_signals
Signal(x).timestamp:
  • contains the timestamp at which the signal x acquisition took place (datetime type); or, the frequency at which signal x was acquired by the sensor
  • It may be have flexible number of elements i.e. (50000 x 1) or (100 x 1) data points
'30-Mar-2018 14:18:48'
'30-Mar-2018 16:32:28'
'30-Mar-2018 16:56:16'
'30-Mar-2018 16:57:30'
'30-Mar-2018 16:58:28'
'30-Mar-2018 16:59:25'
'30-Mar-2018 16:59:54'
'30-Mar-2018 17:00:51'
'30-Mar-2018 17:01:49'
'30-Mar-2018 17:02:46'
...............etc......
Signal(x).values:
  • contains values corresponding to timestamps mentioned above (double type)
timestamp:
  • contains timestamp (datetime type)
  • It has fixed number of elements i.e. (2000 x 1) data points
'30-Mar-2018 16:40:08'
'30-Mar-2018 16:40:09'
'30-Mar-2018 16:44:37'
'30-Mar-2018 16:44:37'
'30-Mar-2018 16:44:38'
'30-Mar-2018 16:56:15'
'30-Mar-2018 16:57:00'
'30-Mar-2018 16:57:29'
'30-Mar-2018 16:57:58'
'30-Mar-2018 16:58:27'
'30-Mar-2018 16:58:56'
...............etc......
How can I fit the values of Signal(x).timestamps in the time intervals of timestamps which are fixed?
If there are more than 1 values for the time interval, we can take the average of values for each time interval.
If there are no values for the time intervals, we can put 0 corresponding to that time interval.
Please help.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by