【发布时间】:2016-08-18 10:14:43
【问题描述】:
我有一堂课:
namespace XMLParserAverage11
{
public class cPoint
{
public string point;
public string time;
public double xPoint;
public double yPoint;
public double StdDevX;
public double StdDevY;
public string csv;
public cPoint(string n, double x, double y)
{
this.point = n;
xPoint = x;
yPoint = y;
}
}
}
用于存储读取XML文件得到的信息,然后放入
List<cPoint> Sorted
我想做的是将“xPoint”存储到一个数组中,将“yPoint”存储到另一个数组中,用于所有“点”that has the same value。这样我最终可以使用 Statistics.PopulationStandardDeviation()from Mathnet.Numerics NuGet 包,它需要一个双数组,并计算 List Sorted 中每个相同“点”的 xPoint 和 yPoint 的总标准偏差。
if (measurementType == "Body")
{
double a = Convert.ToDouble(xOffset);
double b = Convert.ToDouble(yOffset);
cPoint Point = new cPoint(location, a, b);
Point.time = endTime;
// Point.point = location;
// Point.xPoint = Convert.ToDouble(xOffset);
// Point.yPoint = Convert.ToDouble(yOffset);
sorted.Sort((x, y) => x.point.CompareTo(y.point));
// double[] balanceX = {Point.xPoint};
// double[] balanceY = {Point.yPoint};
if (sixSig == true)
{
List<cPoint> pointList = new List<cPoint>();
// Select all the distinct names
List<string> pointNames = location.Select(x => xOffset).Distinct().ToList();
foreach (var name in pointNames)
{
// Get all Values Where the name is equal to the name in List; Select all xPoint Values
double[] x_array = pointList.Where(n => n.point == name).Select(x => x.xPoint).ToArray();
Point.StdDevX = Statistics.StandardDeviation(x_array);
// Get all Values Where the name is equal to the name in List; Select all yPoint Values
double[] y_array = pointList.Where(n => n.point == name).Select(x => x.yPoint).ToArray();
Point.StdDevY = Statistics.StandardDeviation(y_array);
}
csvString = Point.time + "," + Point.point + "," + Point.xPoint + "," + Point.yPoint + "," + Point.StdDevX + "," + Point.StdDevY;
Point.csv = csvString;
sorted.Add(Point);
}
else
{
csvString = endTime + "," + location + "," + xOffset + "," + yOffset;
Point.csv = csvString;
sorted.Add(Point);
}
}
我的输出最终将类似于this。
显然我是一个初学者,所以任何帮助将不胜感激。
【问题讨论】:
-
您的代码有点混乱。
sorted填充在哪里? ,在最后一行?你计算PopulationStandardDeviation只有 1 个值吗?如果您使用来自balanceX的相同单个值,为什么在 foreach 循环中期望a和b有两个不同的结果? -
这听起来像是 XY 问题
-
@Mong Zhu 有大约 500 行额外的代码我不想发布,但
sorted在另一个类中被初始化为cPoint列表。一切最初都存储在cPoint Point中,然后在完成所有计算等后添加到sorted。
标签: c# arrays list standard-deviation mathnet-numerics