6
double[] tab = new double[10];

I know I can gen minimum by tab.Min().

double[,] tab = new double[10,2]; 

This is table of coordinates, in 2nd index 0 is x and 1 is y. There are 10 points.

How can I get minimum (and maximum) value of x and y?

In other words:

minX is the smallest value in 1st column (second index=0 e.g tab[xxx, 0]);
minY is the smallest value in 2nd column (second index=1 e.g tab[xxx, 1]);

6
  • I'm not sure what you are trying to get. You want the smallest pair (x,y) -- i.e., closest to the origin or are you trying to get the boundaries of the region -- min/max in each coordinate? Commented Jan 9, 2011 at 21:26
  • 2
    Point[] tab = new Point[10]; That's an array of coordinates. Commented Jan 9, 2011 at 21:27
  • @tvanfosson No he wants to get the minimum of a column. Commented Jan 9, 2011 at 21:28
  • @Jani - why do you say that? He says he wants minimum (and maximum) value of x and y. I'm just not sure whether he wants the length of each vector or is looking for the vectors with the min/max components in x and y. Commented Jan 9, 2011 at 21:33
  • Seems that I didn't understand it completely, lets wait till the OP clarify about what he wants Commented Jan 9, 2011 at 21:44

2 Answers 2

7
var doubles = new double[4,2]{{1,2},{4,5},{7,8},{9,1}};
var min = System.Linq.Enumerable.Range(0, 4).Select(i => doubles[i, 1]).Min();

OR

var doubles = new double[4,2]{{1,2},{4,5},{7,8},{9,1}};
var min = System.Linq.Enumerable.Range(0, doubles.GetUpperBound(0)+1)
                                .Select(i => doubles[i, 1]).Min();
Sign up to request clarification or add additional context in comments.

Comments

0
double minX = tab[0,0], minY = tab[0,1];
String coordinate = "X";

foreach (double number in tab)
{
    if (coordinate == "X")
    {
        if(number < minX)
            minX = number;

        coordinate = "Y";
    }
    else if (coordinate == "Y")
    {
        if (number < minY)
            minY = number;

        coordinate = "X";
    }
}

1 Comment

Instead of string coordinade I would use int index=0 and change it later to 1. I wanted to do this in similiar way to tab.Min(). I want that I can check each element in search for minimum.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.