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
 LabTalk Forum
 finding fit error for movslope function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

aengwall

3 Posts

Posted - 05/22/2018 :  5:21:20 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Does anyone have an idea how to associate or extract error values for the fits found with the movslope function? My ideal output would be one column with Fx=movslope(x,y,interval) and then a yEr column with the fit errors beside it for easy plotting.

Thanks for your help.

yuki_wu

896 Posts

Posted - 05/23/2018 :  04:37:39 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You could write a piece of script to loop over the subranges and then perform linear fitting on the subrange respectively. Take an example:
int nRows = wks.nRows;
int nInterval = 5;
range raErr = col(3);
range rbErr = col(4);
for(int ii = 1; ii < (nRows/nInterval); ii++)
{
	int nBegin = 1 + (ii - 1) * nInterval;
	int nEnd = 5 + (ii - 1) * nInterval;
	range ee = [Book1]Sheet1!(1,2)[$(nBegin):$(nEnd)];
	fitlr iy:=ee;
	raErr[$(nBegin)] = fitlr.aerr;
	rbErr[$(nBegin)] = fitlr.berr;
}

You could find more details of fitLR X-Function here:
https://www.originlab.com/doc/X-Function/ref/fitLR

Regards,
Yuki
OriginLab

Edited by - yuki_wu on 05/23/2018 04:38:00 AM
Go to Top of Page

aengwall

3 Posts

Posted - 05/23/2018 :  4:51:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Yuki, your reply was very helpful. I hope you can help me with one further refinement. How would I go about setting the interval to be a function of change in time (the first column), rather than a set number of data points? I had been using an additional column of Fx=20/Diff(A) to determine the interval of data points per 20 seconds, but I'm not sure how to translate that into the script.
Go to Top of Page

aengwall

3 Posts

Posted - 05/23/2018 :  8:57:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Actually, I think I've just about got it:

int nRows = wks.nRows;
int maxt = max(col(G));
int nInterval = 50;
int zerot=Index(0,col(G))
range b= X;
range rbErr = Y;
for(int ii = 1; ii < (maxt/nInterval); ii++)
{
int nBegin = zerot + Index((ii - 1) * nInterval,col(G));
int nEnd = zerot + Index((ii) * nInterval,col(G));
range ee = (G,O)[$(nBegin):$(nEnd)];
fitlr iy:=ee;
b[$((nBegin+nEnd)/2)] = fitlr.b;
rbErr[$((nBegin+nEnd)/2)] = fitlr.berr;
}


except I'm no longer getting an output for the slope b, just the error. I welcome any thoughts for troubleshooting.
Go to Top of Page

yuki_wu

896 Posts

Posted - 05/23/2018 :  10:54:49 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I think you missed the semicolon at the end of Line 4, it should be:
int zerot=Index(0,col(G));

Also, to avoid conflict with column short name, it is recommended to rename “range b” , such as “range rb”. Please refter to the variable naming rules here:
https://www.originlab.com/doc/LabTalk/guide/Data-Types-and-vars#Variable_Naming_RulesVariable_Naming_Rule

Hope it helps.

Regards,
Yuki
OriginLab
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