Hi,
Origin C code for computing centroid using your formula is pasted below.
Here are some instructions:
1> version 7 SR3 or higher recommended - get the SR3 patch if you don't have it already
2> Open Code Builder (menu: View->Code Builder)
3> Create new C file (menu: File->New), give name such as centroid.c
4> Cut and paste code from below into window, and compile and build
5> Now you can go to script window and type the command:
centroid %c
OR
centroid data1_b
etc.
You should see output such as:
centroid %c;
Curve name: Gaussian_Ampl
X range: 8.000000 to 41.000000
Centroid = 24.827855
6> To make this funciton available to you in all Origin sessions, go back to Code Builder, and drag-and-drop your C file from User folder to System folder in the Code Builder Workspace tree. From now on, any time you start Origin, your function will be compiled and ready to use. Note that this requires SR3 - the tree strucutre was added in SR3.
Easwar
OriginLab.
void centroid(string strCurve)
{
Curve crv( strCurve );
Dataset dsX;
crv.AttachX(dsX);
if( !crv || !dsX )
{
printf("%s is not a valid curve!\n", strCurve);
return;
}
int iBegin = crv.GetLowerBound();
int iEnd = crv.GetUpperBound();
double dCentroid = 0, dSum = 0;
for( int j = iBegin; j <= iEnd; j++)
{
dCentroid += dsX[j] * crv[j];
dSum += crv[j];
}
dCentroid /= dSum;
printf("Curve name: \t %s\n", strCurve);
printf("X range: \t %f to %f\n", dsX[iBegin], dsX[iEnd]);
printf("Centroid = \t %f\n\n", dCentroid);
}