J'ai une classe:changements de trouver dans une liste, puis stocker des valeurs spécifiques dans un tableau 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;
}
}
}
Ceci est utilisé pour stocker des informations obtenues à la lecture d'un fichier XML, puis il est mis en
List<cPoint> Sorted
Ce que je voudrais faire est de stocker le "xPoint" dans un tableau et le "yPoint" dans un autre tableau pour tous "point" that has the same value. C'est ainsi que je peux finalement utiliser Statistics.PopulationStandardDeviation()
de Mathnet.Numerics NuGet qui nécessite un double tableau et calculer l'écart-type total de xPoint et yPoint par le même "point" dans List Sorted.
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);
}
}
Ma sortie finira par ressembler à this.
Évidemment, je suis un débutant donc toute aide serait grandement appréciée.
Votre code est un peu confusing.where est 'sorted' peuplée? , dans la dernière ligne? Calculez-vous 'PopulationStandardDeviation' avec seulement 1 valeur? pourquoi attendez-vous dans la boucle foreach deux résultats différents pour 'a' et' b' si vous utilisez la même valeur unique de 'balanceX'? –
cela ressemble à un problème XY – Neil
@Mong Zhu il y a environ 500 lignes de code supplémentaires que je ne voulais pas publier mais 'trié 'est initialisé comme une liste' cPoint' dans une autre classe. Tout est stocké initialement dans 'cPoint Point', puis ajouté à' trié' quand tous les calculs sont effectués. –