The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 Sparse matrix
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Rimmer

Sweden
25 Posts

Posted - 11/12/2003 :  07:47:40 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello

I have an xyz data set which I create a sparse matrix from. The resulting matrix has a number of missing value due to the nature of the data of the form

5 - - - - 5 - - - - 5
4 - - - - 3 - - - - 2
- 6 - - - 4 - - - 4 -
- - 7 - - 7 - - 3 - -
- - - 4 - 2 - 1 - - -

I want to change the inner missing data so that the matrix would read as follows

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 - - -

ie just fill in the blanks based on the values on either side of the missing data

Is there some way of accomplishing this

Thanks

Michael


easwar

USA
1965 Posts

Posted - 11/13/2003 :  1:46:08 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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];
}
}
}
}


Go to Top of Page

Rimmer

Sweden
25 Posts

Posted - 11/13/2003 :  3:32:50 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
This works great. Thank you

Mick
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000