Assuming you have a test data vector x
, one way to obtain all the segments of x
under a certain tolerance y_tol
is:
main.m1062 chars40 lines
This code loops through the data points, and every time the difference between a point and the previous one is smaller or equal to y_tol
, it adds it to the current segment. When the difference exceeds y_tol
, it ends the current segment. The start and end indices of each segment are stored in the start_idx
and end_idx
vectors, respectively. Finally, the code displays the indices of the segments found.
gistlibby LogSnag