You can define a function with the following inputs: previous result, new result, and a percentage threshold. The function will compute the difference between the two results and check if it is higher than the percentage threshold of the previous result.
Here is an example implementation:
main.m175 chars5 linesThis function first computes the difference as the absolute value of the ratio between the two results. It then compares this difference to the threshold value and returns a boolean indicating whether a test should be applied.
You can use this function with your own values like this:
main.m126 chars6 lines
This will return true since the difference between 100 and 120 is 20%, which is higher than the threshold of 10%.
Note that this implementation assumes that the two results are nonzero. You may want to add additional checks if zero is a possible value.
gistlibby LogSnag