The dictionary part isnt working. can anybody help??
string path = @"C:\1\";
string[] file1_Lines = File.ReadAllLines(path + @"TraceSet.csv");
string file2 = File.ReadAllText(path + @"SBoxOutput.csv");
string[] file2_Lines = file2.Split(new string[]{"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
//creating 2 lists for average values of file1 and file2:
List<float> averageFile1 = new List<float>();
List<float> averageFile2 = new List<float>();
//filling list1 - with average calculation of the file1 (row average):
foreach (string line in file1_Lines)
{
string[] columns = line.Split(';');
float fAvg = 0f;
for (int i = 1; i < columns.Length; i++)
{
float value = Convert.ToSingle(columns[i]);
fAvg += value;
}
//get the average and add to list:
fAvg = fAvg / (columns.Length - 1);
averageFile1.Add(fAvg);
}
//filling list2 - with average calculation of the file2 (column average):
//creating a dictionary collection for get the sum of values in the columns
Dictionary<int, int> dic = new Dictionary<int, int>();
for (int i = 0; i < file2_Lines.Length; i++)
{
string[] lineValues = file2_Lines[i].Split(';');
for (int j = 0; j < lineValues.Length; j++)
{
int intValue = Convert.ToInt32( lineValues[j]);
if (dic.ContainsKey(j))
dic = dic.ToDictionary(d => d.Key, d => d.Key == j ? d.Value + intValue : d.Value);
else
dic.Add(j, intValue);
}
}
//get the average into the list2 from the dictionary:
int rows = file2_Lines.Length;
foreach (KeyValuePair<int, int> _value in dic)
{
averageFile2.Add(_value.Value / rows);
}
//
//
//subtract the average of row 1 from the average of column 1 and reapeat for each row and column
//
List<float> newList = new List<float>();
for (int i = 0; i < averageFile2.Count; i++)
{
for (int j = 0; j < averageFile1.Count; j++)
{
if (j == i)
{
float _newValue = averageFile2[i] - averageFile1[j];
newList.Add(_newValue);
break;
}
}
}
//"newList" now holds the values you wanted!!!
Thank You