0

I am trying to process a large amount of data looking for cyclical behavior. In other words, data that jumps back and forth between two respective values. I have tried many different solutions, but all of them give false positives for identifying the behavior. Here is an example of what I am looking for if the first column is time and the second column is altitude: [0 1000; 5 2000; 10 1000; 15 2000; 20 1000]. In this example, the altitude is cycling back and forth between 1000 and 2000ft. If anyone could give me a hand, it would be greatly appreciated. I am writing in MATLAB.

N. Allen
  • 3
  • 3

1 Answers1

0

if it's only for two sequential elements you can use 1D filtering like that:

A =  [-5 8000; 0 1000; 5 2000; 10 1000; 15 2000; 20 1000; 25 3000; 30 1000];
b = A(:,2);
% filtering with 2 elemnts vector. the imaginary part is to avoid
% false-positives from adding different numbers to the same sum
x = conv(b,[1;1j],'valid');
% find unique values and their number of occurrences
[C,ia,ic] = unique(x,'stable');
counts = histcounts(ic,[1:max(ic),inf]);
multiCounts = counts > 1;
% find the repeating patterns
patternFirstIdxs = ia(multiCounts);
patterns = [b(patternFirstIdxs),b(patternFirstIdxs + 1)];

if you want to find all the occurrences of each pattern look at ia or use k = strfind(b,pattern) for each of them.

user2999345
  • 4,195
  • 1
  • 13
  • 20
  • It isn't just for two sequential elements, there will likely be multiple values. But I will look into ia or k = strfind(b,pattern). I appreciate your response! – N. Allen Apr 07 '17 at 14:44