I have this class for storing data read from an XML file:
public class cPoint
{
public string point;
public string time;
public double xPoint;
public double yPoint;
public string csv;
}
I then have another class to scour the XML file and store data in List<cPoint> sorted = new List<cPoint>(); which is global:
...
if (measurementType == "Body")
{
cPoint Point = new cPoint();
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));
csvString = endTime + "," + location + "," + xOffset + "," + yOffset;
Point.csv = csvString;
sorted.Add(Point);
}
and finally I use this code in my main to sort through the distinct names in sorted and calculate the standard deviation of the associated xPoint and yPoint:
List<string> PointNames = sorted.Select(x => x.point).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 = sorted.Where(n => n.point == name).Select(x => x.xPoint).ToArray();
string StdDevX = Convert.ToString(Statistics.StandardDeviation(x_array));
// Get all Values Where the name is equal to the name in List; Select all yPoint Values
double[] y_array = sorted.Where(n => n.point == name).Select(x => x.yPoint).ToArray();
string StdDevY = Convert.ToString(Statistics.StandardDeviation(y_array));
//Something along these lines:
//sorted.csv += StdDevX "," + StdDevY;
}
List<string> CSV = sorted.Select(x => x.csv).ToList();
WriteToFile(Title);
WriteToFile(CSV);
What I would like to do is add a string of StdDevX + "," + StdDevY to each sorted.csv with a distinct name. As you can see at the bottom of my code, I'm writing sorted.csv to a an excel file (as a comma separated value). Here is my expected output to illustrate what I need.
Any help would be great guys