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
 LabTalk Forum
 polynomial fit of frequency counts

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
coll@inia. Posted - 11/05/2015 : 01:37:51 AM
Origin 2015
Operating System:Windows 8

I want to automaze by LabTalk, 4-5 columns of data.
1st- I need to distribute the values among oercent frequencies separated in bin zizes of 0.08 appearing nearby in the worksheet

2nd. Draw the resulting XYYYY columns of frequencies in a line graph without symbols and with w wide line of 4

3th oerform a polynomial fit of 9th order with fis intercept to 0, sustituting the line drawings

I require to do all this manually many many times. Can an script we designed to automatize all these? Am I asking too much?

Thank you, julio
5   L A T E S T    R E P L I E S    (Newest First)
coll@inia. Posted - 11/07/2015 : 05:04:34 AM
Here is the final code.
Up to now it worked fine for different numbers of columns.
Still might contain some bugs..........
Thank you Sean!

//get number of first column
getnumber -s FirstColNumber bb1 (number of first column);
getnumber -s NumberOfCols nn (number of columns);
ff1=bb1+nn-1;
string pageName$ = page.name$; // get the window name

//frequency counts
freqcounts -r 2 irng:=col($(bb1):$(ff1)) inc:=0.08 center:=1 end:=0 freq:=1 count:=0 cumulcount:=0 rd:=[<input>]<input>;

//1st drawings
bb2=bb1+nn+1;
ff2=bb2+nn-1;
plotxy iy:=(col("Bin Center"),col($(bb2):$(ff2))) plot:=200 color:=1 ogl:= [%(graphName$)]Layer1!; //200 line plot
string graphName$ = page.name$; //get the layer name
set %C -w 500; // 1pts active data set

win -a %(pageName$);
For(ii=1;ii<=nn;ii++)
{
bb3=nn+1+ii; //col to be fit
bb4=2*nn+1+2*ii;//col to be filled with bin centers
ff4=bb4+1; //col to be filled with fitted
fitpoly iy:=(col("Bin Center"),col($(bb3))) polyorder:=9 fixint:=1 intercept:=0 oy:=($(bb4):$(ff4)) -r 2;
};

//2nd fitted drawings
For(ii=1;ii<=nn;ii++)
{
bb2=bb1+nn+1;
bb3=nn+1+ii; //col to be fit
bb4=2*nn+1+2*ii;//col to be filled with bin centers
ff4=bb4+1; //col to be filled with fitted
plotxy iy:=((col($(nn+1)),col($(ff4)))) plot:=200 color:=$(ii) ogl:=[%(graphName$)]Layer1!; //[FitGraph1]
set %C -w 2000; //set width 4
};

//Final format worksheet
for(kk=1;kk<=ff4;kk++)
{
wks.col$(kk).digitmode=1;
wks.col$(kk).digits=2;
wks.col$(kk).width=4;
};
for(kk=nn+1;kk<=ff2;kk++)
{
wcellcolor $(kk) C:=color(230,230,230);
};
wcellcolor $(nn+1) c:=color(255,255,200);

//formatting graph
win -a %(graphName$); //FitGraph1;
layer1.x.from=0;
layer1.y.from=0;
For(jj=1;jj<=nn;jj++) //change FittedLineWidth to 4pts
{
range rr=1!$(nn+jj);
set rr -w 2000;
};
page.longname$="FitGraph";
coll@inia. Posted - 11/06/2015 : 04:27:41 AM
THANK YOU SEAN !
I really appreciatted your help
It worked fine now.

I am introducing variables instead of numeric values so as to make the script more useful to several variants I have.

I will be back with the final solution (I hope) as soon as I managed to make it work, in case you and/or other would be interested.

Thank you again, & "salu2" from SPAIN!
julio
SeanMao Posted - 11/05/2015 : 10:40:31 PM
Hi,

Please try the code below:


[Freq]
//frequency counts
freqcounts -r 2 irng:=col(1:3) inc:=0.08 center:=1 end:=0 freq:=1 count:=0 cumulcount:=0 rd:=[<input>]<input>; 

[Plot]
//drawing
plotxy iy:=(col("Bin Center"),col(5:7)) plot:=200; //200 line plot
set %C -w 2000; // 4pts active data set

[Fit]
//fitting
win -a Book1; 
wks.ncols = wks.ncols+6;
// Multiple input columns is supported on GUI but not LabTalk
fitpoly iy:=(col("Bin Center"),col(5)) polyorder:=9 fixint:=1 intercept:=0 oy:=(8,9) -r 2; 
fitpoly iy:=(col("Bin Center"),col(6)) polyorder:=9 fixint:=1 intercept:=0 oy:=(10,11) -r 2;
fitpoly iy:=(col("Bin Center"),col(7)) polyorder:=9 fixint:=1 intercept:=0 oy:=(12,13) -r 2;
plotxy iy:=((8,9),(10,11),(12,13)) plot:=200 ogl:=[Graph1]Layer1!; 

[DrawFit]
//drawing fitted curve
win -a Graph1;
layer.plot =4; // Activate added plot
set %C -w 2000; // Set width as 4
// Data plots are grouped, line below actually does nothing
//set %C -c color(green); // Set color as Red


Hope this will be it.

Regards!

Sean
coll@inia. Posted - 11/05/2015 : 05:54:59 AM
GREAT!!
IT ALMOST WORK FULLY!!

It only failed when I am trying to apply it to several columns.
The script works, but stops at the one colum fitting.
It now stands as:

//frequency counts
freqcounts -r 2 irng:=col(1:3) inc:=0.08 center:=1 end:=0 freq:=1 count:=0 cumulcount:=0 rd:=[<input>]<input>;

//drawing
plotxy iy:=col(5:7) plot:=200; //200 line plot
set %C -w 2000; // 4pts active data set

//fitting
win -a Book1;
fitpoly iy:=(col("Bin Center"),col(5:7)) polyorder:=9 fixint:=1 intercept:=0 oy:=(9:11) -r 2;
plotxy iy:=col(9:11) plot:=200 ogl:=[Graph1]Layer1!;

//drawing fitted curve
win -a Graph1;
layer.plot =2; // Activate added plot
set %C -w 2000; // Set width as 4
set %C -c color(red); // Set color as Red

Could you give a last hit?
Thank you !!!!!!!!!
julio
SeanMao Posted - 11/05/2015 : 03:23:41 AM
Hi,

1. freqcounts -r 2 inc:=0.08 rd:=[<input>]<input>;
2. plotxy iy:=col("Count") plot:=200; set %C -w 2000; // 4pts
3. win -a Book1;
fitpoly iy:=(col("Bin Center"),col("Count")) polyorder:=9 fixint:=1 intercept:=0 oy:=(7,8) -r 2;
plotxy iy:=$(wks.ncols) plot:=200 ogl:=[Graph1]Layer1!;
win -a Graph1;
layer.plot =2; // Activate added plot
set %C -w 2000; // Set width as 4
set %C -c color(red); // Set color as Red

Hope this can be some help.

Regards!

Sean

OriginLab Tech.

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