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
 why does this delete half of my y-data?

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
ericharley Posted - 06/03/2006 : 11:52:58 AM
Origin Version (Select Help-->About Origin): OriginPro 7.5 SR6 v7.5885 (B885)
Operating System: Win XP SP2

Whenever I run this (quadratic_loop_correction()), approximately the first half of the y-values for each data set get deleted from the worksheet. Why does this happen? As far as I can tell, I'm only reading data from the worksheet, not trying to change it anywhere.

Probably doesn't matter much what I intend the code to do, in terms of answering my question. However, in case it helps someone to understand what's going on here, I run this code on a plot of hysteresis loops. Since they are loops, the x-values of the curves don't change monotonically - they start at large x ("top" of the loop), go to small x ("bottom" of the loop), and then back up to large x. I divide the loop into segments along the x-axis, and perform a linear fit on both the top segment and the bottom segment. The slope of these fits should be the same; I use the difference between the slopes to calculate the coefficient for a quadratic factor I can use to correct the data.


int seg_midpt_index(int inSeg, int iL, int iU, int iNSeg)
{
//inSeg is the number of the segment of interest (starting from 1)
//iL is lower index for entire range
//iU is upper index for entire range
//iNSeg is the total number of segments the range is divided into
//
//this is set up so integer division only occurs once, so
//rounding errors don't compound
return (iNSeg*(2*iL -1) + (2*inSeg-1) * (iU-iL+1)) / (2*iNSeg);
}


bool quadratic_loop_correction(int iSeg)//number of segments into which
{ //to divide loop
GraphLayer gl = Project.ActiveLayer();
if(!gl)
{
out_str("Active layer is not a graph.");
return false;
}

foreach(DataPlot dp in gl.DataPlots)
{
Curve crvLoop(dp);
double arrCoeffS2a[2];
double arrCoeffS2b[2];
double arrCoeffS1a[2];
double arrCoeffS1b[2];

//linear fits for top of hysteresis loop
fitpoly(crvLoop, 1, &arrCoeffS2a, 1, 2*iSeg);
fitpoly(crvLoop, 1, &arrCoeffS2b, 2*iSeg, 2*iSeg);

//linear fits for bottom of hysteresis loop
fitpoly(crvLoop, 1, &arrCoeffS1a, iSeg, 2*iSeg);
fitpoly(crvLoop, 1, &arrCoeffS1b, iSeg+1, 2*iSeg);

//find average slopes
double dSlope1 = (arrCoeffS1a[1] + arrCoeffS1b[1]) / 2.;
double dSlope2 = (arrCoeffS2a[1] + arrCoeffS2b[1]) / 2.;

//find x values from segment midpoints
Dataset dsX;
crvLoop.AttachX(dsX);//attach dataset to X part of curve
if(!dsX) return false; //return if that didn't work

int iLowerXIndex = dsX.GetLowerIndex();
int iUpperXIndex = dsX.GetUpperIndex();

int iXIndexMidSeg2a = seg_midpt_index(1, iLowerXIndex, iUpperXIndex, 2*iSeg);
int iXIndexMidSeg2b = seg_midpt_index(1, iLowerXIndex, iUpperXIndex, 2*iSeg);
int iXIndexMidSeg1a = seg_midpt_index(iSeg, iLowerXIndex, iUpperXIndex, 2*iSeg);
int iXIndexMidSeg1b = seg_midpt_index(iSeg+1, iLowerXIndex, iUpperXIndex, 2*iSeg);

double dXAvg = (fabs(Curve_x(&crvLoop,iXIndexMidSeg2a)) + fabs(Curve_x(&crvLoop,iXIndexMidSeg2b))
+ fabs(Curve_x(&crvLoop,iXIndexMidSeg1a)) + fabs(Curve_x(&crvLoop,iXIndexMidSeg1b))) / 4.;

//calculate value of coefficient for quadratic correction
double dQuadCoeff = (dSlope2 - dSlope1) / (4. * dXAvg);

out_double("quadratic coefficient is ", dQuadCoeff);
}
return true;
}
1   L A T E S T    R E P L I E S    (Newest First)
Deanna Posted - 06/05/2006 : 04:47:02 AM
Hi,

When you call the function
BOOL fitpoly(Curve &cc, int ipolyorder, double *coeff, int inumer, int idenom)
the lower index of the curve CC will be altered.

In fact, the first half of the data is not deleted. If you set the lower index back to one, it will reappear.

The OC code to set the lower index is as follows

cc.SetLowerIndex(1);


Deanna
OriginLab GZ Office

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