Ich habe eine Klasse:Finding Änderungen in einer Liste speichern dann bestimmte Werte in ein Array C#
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;
}
}
}
Dies dient zum Speichern von Informationen aus dem Lesen eine XML-Datei erhalten und dann wird es in
setztList<cPoint> Sorted
Was ich tun möchte ist, speichern Sie die "xPoint" in ein Array und die "YPoint" in ein anderes Array für alle "Punkt" that has the same value. Dies ist so, dass ich schließlich Statistics.PopulationStandardDeviation()
aus dem Mathnet.Numerics NuGet-Paket verwenden kann, das ein doppeltes Array benötigt, und die gesamte Standardabweichung von xPoint und yPoint pro "Punkt" in List Sorted berechnet.
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);
}
}
Meine Ausgabe wird schließlich this ähneln.
Offensichtlich bin ich ein Anfänger, also würde jede Hilfe sehr geschätzt werden.
Ihr Code ist ein wenig confusing.where ist 'sorted' bevölkert? , in der letzten Zeile? Berechnen Sie die 'PopulationStandardDeviation' mit nur 1 Wert? Warum erwarten Sie in der foreach-Schleife zwei verschiedene Ergebnisse für 'a' und' b', wenn Sie denselben Wert von 'balanceX' verwenden? –
das klingt wie ein XY-Problem – Neil
@Mong Zhu gibt es etwa 500 zusätzliche Zeilen Code, die ich nicht posten wollte, aber 'sortierte' wird als' cPoint' Liste in einer anderen Klasse initialisiert. Alles wird anfangs in "cPoint Point" gespeichert und dann zu "sorted" hinzugefügt, wenn alle Berechnungen usw. durchgeführt sind. –