Matrix::GetCellValue
GetCellValue
Description
Get the value of the cell nearest the specified X and Y coordinates.
Syntax
double GetCellValue( double x, double y )
Parameters
- x
- [input] The input x coordinate
- y
- [input] The input y coordinate
Return
Returns the value of the cell nearest the specified X and Y coordinates.
Examples
EX1
// Get the cell value (=Z) nearest the specific coordinates in a matrix
void Matrix_GetCellValue_ex1()
{
// This sample code will print a message like below:
// Target matrix is Matrix1.
// The Min and Max of both X and Y are 0 and 100, respectively.
// Cell value(=Z) nearest (50.1,50.1) is 50.
// Cell value(=Z) nearest (124,124) is NANUM.
// Cell value(=Z) nearest (125,125) is NANUM.
double dZValue;
matrix<double> mat1 = {
{10, 20, 30},
{40, 50, 60},
{70, 80, 90}
};
MatrixPage MatPg1;
MatPg1.Create("Origin");
MatrixLayer MatLy1 = MatPg1.Layers(0);
Matrix Mat1(MatLy1);
Mat1 = mat1;
printf(" Target matrix is %s.\n",Mat1.GetName());
Mat1.SetXMin(0); // Set the X coordinate of 1st column
Mat1.SetXMax(100); // Set the X coordinate of last column
Mat1.SetYMin(0); // Set the Y coordinate of 1st row
Mat1.SetYMax(100); // Set the Y coordinate of last row
printf(" The Min and Max of both X and Y are 0 and 100, respectively.\n");
dZValue = Mat1.GetCellValue(50.1,50.1); // Get Z coordinate at (50.1,50.1)
if(dZValue==NANUM) printf(" Cell value(=Z) nearest (50.1,50.1) is NANUM.\n");
else printf(" Cell value(=Z) nearest (50.1,50.1) is %g.\n", dZValue);
dZValue = Mat1.GetCellValue(124,124); // Get Z coordinate at (124,124)
if(dZValue==NANUM) printf(" Cell value(=Z) nearest (124,124) is NANUM.\n");
else printf(" Cell value(=Z) nearest (124,124) is %g.\n", dZValue);
dZValue = Mat1.GetCellValue(125,125); // Get Z coordinate at (125,125)
if(dZValue==NANUM) printf(" Cell value(=Z) nearest (125,125) is NANUM.\n");
else printf(" Cell value(=Z) nearest (125,125) is %g.\n", dZValue);
}
Remark
Get the value of the cell nearest the specified X and Y coordinates.
See Also
Matrix::SetCellValue
header to Include
origin.h
|