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
 Selecting parts of a dataset in OriginC
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

oconnor

UK
Posts

Posted - 11/19/2004 :  09:25:32 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I'm just starting with Origin C and would like to know how one goes about selecting a range of rows, or subset of a column, to get the mean for example. I have a column that I need to bin from row 1 to 10 and from 11 to 20 etc. What I imagine it looking like would be:

Dataset ds("Data1_A);
vector a=ds[1:10];
vector b=ds[11:20];

Is there an easy way to do this?

Cheers,
Rod.

easwar

USA
1965 Posts

Posted - 11/19/2004 :  09:50:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Rod,

Take a look at the SetLowerBound and SetUpperBound properties of the Dataset object.

You can then write code such as:


dsA.SetLowerBound(2);
dsA.SetUpperBound(7);
BasicStats bsStatVal;
Data_sum(&dsA, &bsStatVal);
printf("%f\n", bsStatVal.min);



Easwar
OriginLab

Go to Top of Page

oconnor

UK
Posts

Posted - 11/19/2004 :  10:14:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Easwar,

That's exactly what I needed to do -except for the fact that I noticed when you use SetLowerBound/SetUpperBound it deletes the data above and below the range you select. Is there a trick around this?

Cheers,
Rod.
Go to Top of Page

easwar

USA
1965 Posts

Posted - 11/19/2004 :  10:58:39 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Rod,

Setting lower and upper bounds on a dataset also set the display range for that dataset. The data does not get deleted, but only that part of the data is displayed, which corresponds to the last setting of lower and upper bounds.

In order to perform analysis independent of the display settings, you need to make a copy of the data into a vector, such as the code below.

Note that in this code, I first get a copy of the data for the specific rows that I want, and then further I am copying this into a temp dataset. This is because the BasicStats call accepts only a dataset. Instead, you can call the NAG library function which accepts vector, thus avoiding having to copy the vector into a temp dataset. Look at the sample project \Samples\Programming\NAG Summary Stas.OPJ and the associated OC file that is attached to that project, on how to call the NAG function. You can also look directly in the programming help file, under the section
Origin C Language Reference->Global Functions->NAG Functions->NAG Simple Calculations on Statistical Data.

Making a copy of a dataset column into a vector for performing analysis also has other benefits. For example, your source dataset may have missing values. Then in the copy the missing values could be removed using vectorbase methods such as Trim(), TrimLeft(), TrimRight() etc. and then you can process the data that remains.

Easwar
OriginLab


void get_stats()
{
// Declare wks
Worksheet wks = Project.ActiveLayer();
if( !wks ) return;

// Point to 2nd column in current wks
Column ccData( wks, 1 );
if( !ccData ) return;

// Copy rows 10 thru 20 to a vector
vector vecSubData( ccData, 9, 19 );
// Place vector in temp dataset to call basic stats
Dataset dsTemp( vecSubData );
BasicStats bsStatVal;
// Get basic stats
Data_sum(&dsTemp, &bsStatVal);
// Print results
printf( "min, max, mean: %f %f %f\n", bsStatVal.min, bsStatVal.max, bsStatVal.mean );
}


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