I want to get the second minimum value of a two dimensional array, my original Array contains a lot of zeros which i can't do anything about them but i want to get the minimum value that's why i thought about this idea, anyone has a clue ? i tried the following order for the lowest value which works. the code i just put it to be ale to post the question and i don't need it to be modified i just want to know how can i get the second minimum value.
low1 = result1.Cast().Min();
for (int m = 0; m < Weights.Count; m++)
{
int offset = m * ListCranelocations.Count;
for (int i = 0; i < ListCranelocations.Count; i++)
{
for (int j = 0; j < ListPickLocations.Count; j++)
{
double x = ListCranelocations[i].Lat - ListPickLocations[j].Lat;
double y = ListCranelocations[i].Lng - ListPickLocations[j].Lng;
R1[i] = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
if ( R1[i] > Clearance )
{
result1[i + offset, j] = Weights[m] * R1[i];
//Console.WriteLine(result1[i, j]);
}
}
}
}
for (int m = 0; m < Weights.Count; m++)
{
int offset = m * ListCranelocations.Count;
for (int i = 0; i < ListCranelocations.Count; i++)
{
for (int j = 0; j < ListSetlocations.Count; j++)
{
double x = ListCranelocations[i].Lat - ListSetlocations[j].Lat;
double y = ListCranelocations[i].Lng - ListSetlocations[j].Lng;
R2[i] = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
if (R2[i] > Clearance )
{
result2[i + offset, j] = Weights[m] * R2[i];
// Console.WriteLine(result2[i, j]);
}
}
}
}
double low = 0;
double low1 = 0;
double low2 = 0;
double low23 = 0;
for (int i = 0; i < result1.GetLength(0); i++)
{
for (int j = 0; j < result1.GetLength(1); j++)
{
for (int k = 0; k < result2.GetLength(0); k++)
{
for (int m = 0; m < result2.GetLength(1); m++)
{
if (!(result1[i, j] == 0) && !(result2[k, m] == 0))
{
result3[i, j] = result1[i, j] + "," + result2[k, m];
// Console.WriteLine(result3[i, j]);
/*
if ((result1[i, j]) > (result2[k, m]))
{
highestMoment[i, j] = result1[i, j];
}
else
{
highestMoment[i, j] = result2[k, m];
}
*/
low1 = result1.Cast<double>().Min();
low2 = result2.Cast<double>().Min();
if (low1 > low2)
{
low = low1;
Index[i, j] = "P";
}
else if (low1 > low2)
{
low = low2;
Index[i, j] = "S";
}
counter++;
}
// Console.WriteLine(highestMoment[i, j]);
}
}
}
}