//如何读取文本文件到文本框中已在我另一文章中说明
int count = this.textBox1.Lines.GetUpperBound(0);
double sum = 0;
double aver = 0;
double mtemp;
double stemp;
int mindex=0;
int sindex=0;
double ll;
double l;
double ma;
double su;
double[] p = new double[count];
double[] a = new double[count];
double[] s = new double[count];
double[] m = new double[count];
double[] array = new double[count];
string[] lines = textBox4.Text.Split('\n');
for (int h = 0; h < count; h++)
{
p[h] = Convert.ToDouble(lines[h]);//存放文本框中的数据
sum = sum + p[h];
}
aver = sum / count;
string straver= aver.ToString("f5");//fN 保留N位,四舍五入
for (int h = 0; h < count; h++)
{
// s[h] = (p[h] - aver);
a[h] = Math.Abs(p[h] - aver);//获取文本框数据与平均值之差的数组,主要围绕数组a进行操作
array[h] = Math.Abs(p[h] - aver);//获取文本框数据与平均值之差的绝对值数组
}
ma = array.Max();
string strma = ma.ToString("f5");
su = array.Min();
string strsu= su.ToString("f5");
mtemp = a[0];
stemp = a[0];
for (int i = 0; i < a.Length; i++)
{
if (mtemp < a[i])
{
mtemp = a[i];
mindex = i + 1;
}
}
for (int j = 0; j < a.Length; j++)
{
if (stemp >= a[j])
{
stemp = a[j];
sindex = j + 1;
}
}
textBox2.Text = "测量数据平均值:" + straver;
textBox2.Text = textBox2.Text + "\r\n" + "测量数据点数:" + count;
textBox2.Text = textBox2.Text + "\r\n" + "测量数据最大偏离平均值:" + strma;
textBox2.Text = textBox2.Text + "\r\n" + "测量数据最小偏离平均值:" +strsu;
textBox2.Text = textBox2.Text + "\r\n" + "最大偏离测量节点数序号:" + mindex;
textBox2.Text = textBox2.Text + "\r\n" + "最小偏离测量节点数序号:" + sindex;