I have two time series:
dat = [0,2,3,0,2,2,0,0,1,0.8,3,4,6,7,4,4,3,0,1,3,2.2,0];
dat2 = dat+.5;
time = 1:length(dat);
plot(time,dat);
hold on;
plot(time,dat2,'r');
I would like to find the region in time that both vectors have the greatest successive number of values greater than one. So, for this particular example, both vectors have values greater than 1 between 10 and 18. However, they also have values greater than one on several other occasions. I can obtain the indices of the values greater than one by first generating a matrix:
data = [dat',dat2'];
And then using find
r1 = data>1;
This will provide me with the location of each value that is greater than one. Next I would like to find at what time (between which rows) are the values > 1 maintained for the longest duration. How can I achieve this?
To find the indices of the longest run of values, you can use the following code:
This results in
This code can be used with a matrix:
This code gives the indices of the longest run of values greater than one in both columns: