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
 maximum in a given range

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
axelletapp Posted - 12/10/2007 : 04:09:19 AM
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);
2   L A T E S T    R E P L I E S    (Newest First)
axelletapp Posted - 12/10/2007 : 09:10:08 AM
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);
}
Deanna Posted - 12/10/2007 : 04:54:19 AM
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

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