string path = "file.txt"; var fileStream = File.OpenRead(path); int averagex = 0; int squaresumx = 0; int xk = 0; int m = 0; for (int i = 0; i < fileStream.Length; i++) { var b = fileStream.ReadByte(); if ((char) b != ',') { xk = xk*10 + (b-48);//-48是ASCII转为数字 } else { averagex += xk; squaresumx += xk*xk; m++; xk = 0; } }
if(xk!=0)//判断是否以分割符结尾
{ averagex += xk; squaresumx += xk * xk;
m++;
} averagex /= m;//求平均值 int x = 0;//你公式里面的X哪儿来的 double Xnormal=(x-averagex)/ Math.Sqrt(squaresumx); }
你公式里面那个X是什么值》?
变量矩阵 x