matrixbase::Fix
Fix
Description
Round each cell of this matrix to the nearest integer (toward zero).
Syntax
int Fix( matrixbase & mbFix )
Parameters
- mbFix
- [output] matrix containing the results
Return
Returns 0 on success and a non-zero error code on failure.
Examples
EX1
void matrixbase_Fix_ex1()
{
int rc;
matrix<double> mat1 = {
{ 0.0, 0.1, 1.0, 1.1, 1.5, 1.9},
{ 999, -0.1, -1.0, -1.1, -1.5, -1.9}
};
mat1[1][0]=NANUM; // set row=2,col=1 to NANUM
rc=mat1.Fix(mat1);
if(rc!=0) printf("Error: Fix failed. Error Code=%d\n",rc);
else{
printf("The matrix is:\n");
for(int ii=0; ii< mat1.GetNumRows(); ii++){
for(int jj=0; jj< mat1.GetNumCols(); jj++)
printf("%g ", mat1[ii][jj]);
printf("\r\n");
}
}
}
EX2
#define MAKEMAT(X) MatrixLayer MatLy##X;MatLy##X.Create();Matrix Mat##X(MatLy##X)
// Apply various integer-making functions to a matrix
void matrixbase_Fix_ex2()
{
int rc;
matrix<double> mat1 = {
{ 0.0, 0.1, 1.0, 1.1, 1.5, 1.9},
{ 999, -0.1, -1.0, -1.1, -1.5, -1.9}
};
mat1[1][0]=NANUM; // set row=2,col=1 to NANUM
PageBase pgbase;
MAKEMAT(1);
pgbase = Project.Pages(); // Get the active page
pgbase.Rename("Original");
Mat1 = mat1;
// Change cells to floor values
MAKEMAT(2);
pgbase = Project.Pages();
pgbase.Rename("Floor");
rc=Mat1.Floor(Mat2);
if(rc!=0) printf("Error: Floor failed. Error Code=%d\n",rc);
else printf("%s matrix is created.\n",Mat2.GetName());
// Change cells to fix values
MAKEMAT(3);
pgbase = Project.Pages();
pgbase.Rename("Fix");
rc=Mat1.Fix(Mat3);
if(rc!=0) printf("Error: Fix failed. Error Code=%d\n",rc);
else printf("%s matrix is created.\n",Mat3.GetName());
// Change cells to round values
MAKEMAT(4);
pgbase = Project.Pages();
pgbase.Rename("Round");
rc=Mat1.Round(Mat4);
if(rc!=0) printf("Error: Round failed. Error Code=%d\n",rc);
else printf("%s matrix is created.\n",Mat4.GetName());
// Change cells to ceil values
MAKEMAT(5);
pgbase = Project.Pages();
pgbase.Rename("Ceil");
rc=Mat1.Ceil(Mat5);
if(rc!=0) printf("Error: Ceil failed. Error Code=%d\n",rc);
else printf("%s matrix is created.\n",Mat5.GetName());
}
Remark
Round each cell of this matrix to the nearest integer (toward zero). Notice the differences of Round, Fix, Floor and Ceil.
See Also
matrixbase::Floor, matrixbase::Round, matrixbase::Ceil
header to Include
origin.h
|