Matrix::SetCellValue

Description

Set the value of the cell nearest the specified X and Y coordinates.

Syntax

BOOL SetCellValue( double x, double y, double dValue )

Parameters

x
[input] The input x coordinate
y
[input] The input y coordinate
dValue
[input] The new cell value

Return

Returns TRUE on success and FALSE on failure.

Examples

EX1

// Set the cell value at the specified (X,Y) coordinatein a matrix
void Matrix_SetCellValue_ex1()
{
// Target matrix is Matrix1.
// Change the view mode by View:Show X/Y menu command.
// Observe the cell value: 999 at (0,1).
// Observe the cell value: '--' at (5,5).
// Error: SetCellValue failed at (100,100).
// 
    matrix<double> mat(4, 5);
    mat = 0;

    MatrixPage MatPg;
    MatPg.Create("Origin");
    MatrixLayer MatLy = MatPg.Layers(0);
    Matrix Mat(MatLy);
    Mat = mat;

    //You can change the view mode by View: Show X/Y menu command to set XY range
    Mat.SetXMin(0); Mat.SetXMax(10); // Set the X range
    Mat.SetYMin(0); Mat.SetYMax(7.5); // Set the Y range
    printf("  Target matrix is %s.\n",Mat.GetName());
    
    BOOL bRet;
    bRet=Mat.SetCellValue(0, 1, 999); // Note Cell(0,0)==999
    if(!bRet) printf("  Error: SetCellValue failed at (0,1).\n");
    else printf("  Observe the cell value: 999 at (0,1).\n");
    
    bRet=Mat.SetCellValue(5, 5, NANUM); // Note Cell(5,5) is missing
    if(!bRet) printf("  Error: SetCellValue failed at (5,5).\n");
    else printf("  Observe the cell value: '--' at (5,5).\n");
    
    bRet=Mat.SetCellValue(100.0, 100.0, 123); //x and y is out of the range,assigning value failed
    if(!bRet) printf("  Error: SetCellValue failed at (100,100).\n");
    else printf("  Observe the cell value: 123 at (100,100).\n");
}

Remark

Set the value of the cell nearest the specified X and Y coordinates.

See Also

Matrix::GetCellValue

header to Include

origin.h