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
 maximum in a given range
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

axelletapp

Switzerland
Posts

Posted - 12/10/2007 :  04:09:19 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5 SR6
Operating System: XP

I would like to write a small routine which shift curve, by finding the maximum (in the y axis) and shift it (along x axis) to a given theoretical x value.

The following code works, but xatymax finds maximum in the entire curve. I would like to limit to say (+- delta) around the theoretical value. Probably an easy question: how can i specify this range ?

Thanks for your input.

-------------

Worksheet wks = Project.ActiveLayer();
if(!wks)
{
printf("The active layer is not a worksheet, or there is nothing in the project");
}
else
printf("Worksheet %s has %d columns\n",wks.GetPage().GetName(),wks.GetNumCols());
if(wks.GetNumCols()==2) {
int colnum = wks.AddCol(); //Add a new column
}
Curve crv(wks, 0,1);
double dXatYmax = xatymax(crv);
printf("Value of X at maximum Y is %fs degree.\n", dXatYmax);
Dataset xvalue(wks,0);
Dataset shifted(wks,2);
shifted = xvalue - (dXatYmax - maximumpeak);

Deanna

China
Posts

Posted - 12/10/2007 :  04:54:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Axelletapp,

You can use the following function to find the maximum Y value and the corresponding X value for part of a curve. Please use the parameters iLowerBound and iUpperBound to select this part of the curve.


void test6272(int iLowerBound = 0, int iUpperBound = -1)
{

Dataset dsA("Data1_A");
Dataset dsB("Data1_B");
Dataset dsTemp(dsB); //Create a copy of column B


dsTemp.SetLowerBound(iLowerBound);
dsTemp.SetUpperBound(iUpperBound);

double dMin, dMax;
uint iMin, iMax;
dsTemp.GetMinMax(dMin, dMax, &iMin, &iMax);
out_double("Maximum Y = ", dMax);
out_double("X for maximum Y= ",dsA[iMax]);


}


Deanna
OriginLab Technical Services
Go to Top of Page

axelletapp

Switzerland
Posts

Posted - 12/10/2007 :  09:10:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the quick reply.

Actually what i want is the following:

Move the curve in the x direction, by picking an experimental peak (not necessary the absolute maximum of the curve), which is to be found in a given range around a theoretical value and move the curve accordingly to this shift.


So i could adapt your code:


void shiftcurverange(double maximumpeak, double range = 1.0)
{
Worksheet wks = Project.ActiveLayer();
if(!wks)
{
printf("The active layer is not a worksheet, or there is nothing in the project");
}
else
printf("Worksheet %s has %d columns\n",wks.GetPage().GetName(),wks.GetNumCols());

if(wks.GetNumCols()==2) {
int colnum = wks.AddCol(); //Add a new column
}
Dataset dsA(wks,0); // declare column 1 as original x value
Dataset dsB(wks,1); // declare column 2 original y value
Dataset dsBTemp(dsB); // create a copy of column B


double dMin, dMax;
uint iMin, iMax;
dsBTemp.GetMinMax(dMin, dMax, &iMin, &iMax);
out_double("Absolute Maximum Y (counts) = ", dMax);


int r1,r2; // lower and upper X values for max search in Y values

int i1 = dsA.GetLowerBound(); // save lower bound
int i2 = dsA.GetUpperBound(); // save upper bound
for(int i=i1; i<i2; i++)
{
if( dsA[i]>= (maximumpeak - range) ) break;
}
r1 = i<i2 ? i : i1;
for(i=r1+1; i<=i2; i++)
{
if( dsA[i]>=(maximumpeak + range) ) break;
}
r2 = i>i2 ? i2 : i;
dsBTemp.SetLowerBound(r1);
dsBTemp.SetUpperBound(r2);

// out_double("Lower index boundary = ", r1 );
// out_double("Uppwer boundary = ", r2);


dsBTemp.GetMinMax(dMin, dMax, &iMin, &iMax);
out_double("Maximum Y (counts) = ", dMax);
out_double("X for maximum Y (deg)= ",dsA[iMax]);
out_double("shift angle (deg)= ",dsA[iMax] - maximumpeak);
Dataset shifted(wks,2);
shifted = dsA - (dsA[iMax] - maximumpeak);
}
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