Hi Michael,
You could try the Origin C code pasted here - maybe the way I find the "inside" missing values is not very optmized, but it seems to work!
Easwar
OriginLab.
void fill_missing()
{
// Map active layer to a matrix layer object
MatrixLayer matly = Project.ActiveLayer();
// If object not valid, then what is active is not a matrix
if(!matly)
{
printf("Active layer is not a matrix!\n");
return;
}
// Create Matrix object and attach to this layer
Matrix mat;
mat.Attach(matly);
// Get number of rows and cols in matrix
int iNumRows, iNumCols;
iNumRows = mat.GetNumRows();
iNumCols = mat.GetNumCols();
// If less than 2 cols, just quit
if(iNumCols < 2)
{
printf("Too few columns!\n");
return;
}
// Loop over all rows to find missing values and then fill them
for(int iRow = 0; iRow < iNumRows; iRow++)
{
bool bFoundGap = false;
bool bFoundNumber = false;
int iGapLo, iGapHi;
// Loop over all columns of the current row
for(int iCol = 0; iCol < iNumCols; iCol++)
{
// Look for the first number - this is to ignore missing values "outside"
if(mat[iRow][iCol] != NANUM)
{
bFoundNumber = true;
}
// If number was found, and next cell is missing value, it is start of a gap
if(bFoundNumber && (NANUM == mat[iRow][iCol]))
{
iGapLo = iCol;
bFoundGap = true;
bFoundNumber = false;
}
// If in gap and next value is number, then that means end of gap - so need to fill
if(bFoundGap && bFoundNumber)
{
iGapHi = iCol - 1;
bFoundGap = false;
// Fill half of the gap with number from left, and other half with number from right
int iGapLength = iGapHi - iGapLo + 1;
if(iGapLength > 1)
{
for(int ii = iGapLo; ii < iGapLo + iGapLength / 2; ii++)
mat[iRow][ii] = mat[iRow][iGapLo - 1];
for(ii = iGapLo + iGapLength / 2; ii <= iGapHi; ii++)
mat[iRow][ii] = mat[iRow][iGapHi + 1];
}
else
mat[iRow][iGapLo] = mat[iRow][iGapHi + 1];
}
}
}
}