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
 All Forums
 Origin Forum
 Origin Forum
 Sparse matrix

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Rimmer Posted - 11/12/2003 : 07:47:40 AM
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


2   L A T E S T    R E P L I E S    (Newest First)
Rimmer Posted - 11/13/2003 : 3:32:50 PM
This works great. Thank you

Mick
easwar Posted - 11/13/2003 : 1:46:08 PM
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];
}
}
}
}



The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000