One way to find segments of test data under a certain set tolerance is to iterate through the data and check if each element's absolute difference from the previous element is less than the set tolerance. If it is less than the tolerance, then that element is part of the same segment as the previous element. If it is greater than the tolerance, then a new segment starts at that element.
Here's an example code that takes in a test data vector test_data
and a tolerance value tolerance
and returns a cell array containing the start index, end index, and length of each segment that meets the tolerance criteria:
main.m540 chars18 lines
For example, if you have the following test data vector:
main.m76 chars3 lines
You would call the function like this:
main.m48 chars2 lines
The resulting segments
variable would contain the following cell array:
main.m213 chars9 lines
Note that this implementation assumes that the first element of the test data vector is not part of any segment, since it has no previous element to compare to. If you want to include the first element in the first segment, you can modify the code accordingly.
gistlibby LogSnag