/// <summary> /// 判断几个连续数据是否稳定 /// </summary> /// <param name="data">连续的数据</param> /// <param name="threshold">允许的最大变化量</param> /// <returns></returns> public bool IsDataStable(double[] data, double threshold) { for (int i = 1; i < data.Length; i++) { if (Math.Abs(data[i] - data[i - 1]) > threshold) { return false; } } return true; }
方法调用
double[] data = { 1.0, 1.01, 1.02, 1.03, 1.04 }; double threshold = 0.05; // 允许的最大变化量 bool isStable = IsDataStable(data, threshold);
本文来自www.luofenming.com