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 for Programming
 Forum for Origin C
 Cell and missing values
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

peter.cook

UK
356 Posts

Posted - 09/18/2003 :  2:42:41 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I'm scannning a worksheet of numeric data to filter another data set eg

Columns 1 to nCols
Rows 1 to nRows

if %H(Row, Col) < 2 then TestData[Row]=0/0;

Anyway, I used Cell to read all values but this caused problems with missing values so I initially trapped missing values using GetCell and eg

wks.GetCell(Row,Col,strValue);
if (strValue == "--" ) {
// ignore
} else {
wks.Cell(Row,Col,doubleValue);
if (doubleValue < 2 ) {
// record this
};
}

Is there a better way to read off numeric values and yet deal with (trap) missing values?

Cheers,

pete

soapy

China
2 Posts

Posted - 09/21/2003 :  01:34:09 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Missing values will not cause error in Matrices, so I suggest using matrix for filtering instead of worksheet:

matrix mFilter;
mFilter.CopyFromWks(wks); //Copy the whole worksheet to a matrix

And Then you can use matrix as filter:

if((mFilter[Row][Col]!=NANUM)&&(mFilter[Row][Col]<2))
{
//Action;
}

Go to Top of Page

soapy

China
2 Posts

Posted - 09/21/2003 :  01:34:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Missing values will not cause error in Matrices, so I suggest using matrix for filtering instead of worksheet:

matrix mFilter;
mFilter.CopyFromWks(wks); //Copy the whole worksheet to a matrix

And Then you can use matrix as filter:

if((mFilter[Row][Col]!=NANUM)&&(mFilter[Row][Col]<2))
{
//Action;
}

Go to Top of Page

peter.cook

UK
356 Posts

Posted - 09/22/2003 :  07:10:34 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
THanks,

I might try and adopt this. I guess though Origin should be able to cope with these missing values in a worksheet..!

Cheers,

pete

Go to Top of Page

cpyang

USA
1406 Posts

Posted - 09/22/2003 :  5:54:05 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Peter, you are right,

wks.Cell(Row,Col)

should be able to handle missing value, we will need to fix this.

Trackered as 5219


In the meantime, you can write a separate function to get a cell value, as shown below,



double wks_cell(Worksheet & wks, int nr, int nc)
{
double vv = NANUM;
if(nr < 0 || nr >= wks.GetNumRows() || nc < 0 || nc >= wks.GetNumCols())
return vv;

try {
vv = wks.Cell(nr, nc);
}
catch(int nErr)
{
// put codes here if err handling is needed
}

return vv;
}

void test_check_wks_missing()
{
Worksheet wks = Project.ActiveLayer();

for(int ii = 0; ii < wks.GetNumCols(); ii++)
{
for(int jj = 0; jj < wks.GetNumRows(); jj++)
{
double vv = wks_cell(wks, jj, ii);//wks.Cell(jj, ii);
if(is_missing_value(vv) || vv < 2)
{
string str = wks.TCell(jj, ii);
printf("Cell(%d,%d) is no good, it is \"%s\"\n", jj, ii, str);
}
}
}
}







CP


Edited by - cpyang on 09/22/2003 6:35:11 PM
Go to Top of Page

peter.cook

UK
356 Posts

Posted - 10/21/2003 :  08:19:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi CP,

Thanks for reply - will incorporate this, or something similar.

Cheers,

Pete

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