2.1.17.7.3 ocmath_mat_replace_blanks
Description
Fill missing values in a matrix based on neighboring values.
Syntax
int ocmath_mat_replace_blanks( double * pMat, int nRows, int nCols, int iLeft = -1, int iTop = -1, int iRight = -1, int iBottom = -1, int iOptions = MRB_CUSTOM_VALUE, double dValue = 0 )
Parameters
- pMat
- [modify] The input/output matrix. When the function returns, the missing cells in the matrix will be filled;
- nRows
- [input] The number of rows of the matrix (nRows > 1);
- nCols
- [input] The number of columns of the matrix (nCols > 1);
- iLeft
- [input] The searching distance towards left (iLeft >= -1), -1 means search to the left-most matrix element.
- iTop
- [input] The searching distance towards top (iTop >= -1), -1 means search to the top-most matrix element.
- iRight
- [input] The searching distance towards right (iRight >= -1), -1 means search to the right-most matrix element.
- iBottom
- [input] The searching distance towards bottom (iBottom >= -1), -1 means search to the bottom-most matrix element.
- iOptions
- [input] Specifies the replacing flags. This parameter can be a combination of the following values:
- MRB_CUSTOM_VALUE: Default: replace all missing cells by the custom value specified by dValue;
- MRB_MEAN: Replace the missing value by the mean of non-NANUM values;
- MRB_MIN: Replace the missing value by the minimum of non-NANUM values;
- MRB_MAX: Replace the missing value by the maximum of non-NANUM values;
- MRB_NEAREST_NEIGHBOR: Specify the searchin scope. If not set, the function searches all non-NANUM values within the rectangle specified by iLeft, iTop, iRight and iBottom. If set, the function only search nearest non-NANUM values in the same column or the same row confined by iLeft, iTop, iRight and iBottom.
- MRB_IGNORE_LEFT_BORDER: Ignore the cell whose left cells are all missing values;
- MRB_IGNORE_TOP_BORDER: Ignore the cell whose top cells are all missing values;
- MRB_IGNORE_RIGHT_BORDER:Ignore the cell whose right cells are all missing values;
- MRB_IGNORE_BOTTOM_BORDER:Ignore the cell whose bottom cells are all missing values;
- dValue
- [input] The custom value. This parameter is only valid when setting iOptions to MRB_CUSTOM_VALUE;
Return
If the function succeeds, return the number of missing values in the matrix.
If there is any invalid input, return -1.
Examples
EX1
#include <wks2mat.h>
//Before running, make sure a matrixlayer exists and activated in current project
void ocmath_mat_replace_blanks_ex1()
{
MatrixLayer ml = Project.ActiveLayer();
MatrixObject mo = ml.MatrixObjects(0);
int nRows = mo.GetNumRows();
int nCols = mo.GetNumCols();
Matrix& mat = mo.GetDataObject();
int iRet = ocmath_mat_replace_blanks(mat, nRows, nCols, -1, 0, 1, 0,
MRB_MIN | MRB_NEAREST_NEIGHBOR | MRB_IGNORE_LEFT_BORDER | MRB_IGNORE_RIGHT_BORDER);
MatrixPage mp = Project.Pages();
mp.Refresh(true);
printf("%d blanks found.\n", iRet);
}
/*
In above code, if the input matrix is:
5 - - - - 5 - - - - 5
4 - - - - 3 - - - - 2
- 6 - - - 4 - - - 4 -
- - 7 - - 7 - - 3 - -
- - - 4 - 2 - 1 - - -
The output matrix:
5 5 5 5 5 5 5 5 5 5 5
4 4 4 4 3 3 3 3 3 2 2
- 6 6 6 4 4 4 4 4 4 -
- - 7 7 7 7 7 3 3 - -
- - - 4 4 2 2 1 - - -
*/
Remark
See Also
Header to Include
wks2mat.h
Reference
|