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 for Programming
 Forum for Origin C
 Selecting parts of a dataset in OriginC

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
oconnor Posted - 11/19/2004 : 09:25:32 AM
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.
3   L A T E S T    R E P L I E S    (Newest First)
easwar Posted - 11/19/2004 : 10:58:39 AM
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 );
}


oconnor Posted - 11/19/2004 : 10:14:49 AM
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.
easwar Posted - 11/19/2004 : 09:50:11 AM
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


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