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
 Extracting parameters of multiple fits in workbook
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

BennettS

6 Posts

Posted - 05/02/2018 :  07:55:36 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin 2018G (64-bit)
Operating System: Windows 7

Hello,
I'm using the following LabTalk script to facilitate my analysis of ultrasonic data, which runs mostly as intended:

page.active = 1;
//zeropadding for FFT
csetvalue col:=col(A)[1001:10000] formula:="col(a)[1000]+((i-1000)*(col(a)[1000]-col(a)[999]))";
csetvalue col:=col(B)[1001:10000] formula:="0";
//FFT
fft1 col(B) win:=hanning re:=0 im:=0 ap:=0 ri:=0 db:=0 psd:=0;

//preparation for my question, essentially an user input to create an identifier
string comment$="Kommentar";
getn (Comment) comment$;
range cc = 1!col(B);
cc.Comment$ = comment$;
//plot FFT and fit
page.active$ = "FFTResultData1";
plotxy (1,2) plot:=200;
nlbegin 1 func:=Lorentz_3 nltree:=ParamTree;
nlfit;
nlend 1;


1)a side question here: when doing the fit "by hand" using the dialogue box, the graph will show the green lock in the upper left corner, making it possible to rerun/modify the fitting if necessary. With the script, the lock is missing. Is it possible to change that?

2)the fit function I’m using is a custom one with 9 parameters (A1-A3, w1-w3, f1-f3). I have multiple worksheets with my results from different measurements and will be running the script on each one one by one. Now I would like to add something to the script to write the fit parameters in Y columns and the identifier (the range cc) as X into a prepared workbook eg. named “FitResult”, so each run of the script over a new data workbook would add the identifier and parameters in the next free line of “FitResults”

I think I can access the identifier with the range I declared and the parameters probably from nltree somehow, but am at a loss as to how then get them linewise into my result workbook.

Thanks for your help.

yuki_wu

896 Posts

Posted - 05/02/2018 :  11:26:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,
#1 Add a parameter at the end of the nlend X-Function, for example:

nlend 1 2; //Recalculate Mode: Manual
nlend 1 1; //Recalculate Mode: Auto


More info please take a look at this page:
https://www.originlab.com/doc/X-Function/ref/nlend

#2 I suppose you hope to put the value of parameters to the specified cells in a worksheet, right? If so, you can use a range to access a single cell or block cells, for example:

// cell(2,1), row2 of col(1)
range aa = 1[2];
// cell(1,1) to cell(10,3)
range bb = 1[1]:3[10];


More info about Range:
https://www.originlab.com/doc/LabTalk/guide/Range-Notation#Block_of_CellsRange.2C_Block_of_Cells

Hope it helps.

Regards,
Yuki
OriginLab
Go to Top of Page

BennettS

6 Posts

Posted - 05/03/2018 :  04:13:30 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for your help so far, #1 is solved, seems I missed the correct option notation for nlend.

For #2, I’ve thought of a (clunky) workaround following your hint. As I’m prompting for an identifier anyway, I could ask for a row index in the same step and then use a variable in my cell assignment, eg.


string comment$="Kommentar";
r = 1;
getn (Comment) comment$
 (Index) r;
range cc = Sheet1!col(B);
cc.Comment$ = comment$;
//fit part from post above runs

[“FitResults”]Sheet1!col(1)[r] = comment$;
[“FitResults”]Sheet1!col(2)[r] = ParamTree.A1;
[“FitResults”]Sheet1!col(3)[r] = ParamTree.A2;
[“FitResults”]Sheet1!col(4)[r] = ParamTree.A3;
//and so on for the remaining parameters



the problems that I’ve now run into are:
1) using r as row index apparently is not the correct way to create a row variable
2) comment$ can’t be assigned as a cell value, I’m guessing a data type conflict
3) I’m missing something basic about cell designation,
//this works fine, with the right sheet active of course
col(2)[1] = ParamTree.A1;

//these don’t
Sheet1!col(2)[1] = ParamTree.A1;
[“FitResults”]Sheet1!col(2)[1] = ParamTree.A1;

Go to Top of Page

yuki_wu

896 Posts

Posted - 05/06/2018 :  10:22:43 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I think this example could help:
for(int ii = 1; ii < 10; ii++)
{
	[Book1]Sheet2!Cell($(ii),2) = 10;
}

Regards,
Yuki
OriginLab

Edited by - yuki_wu on 05/06/2018 10:23:26 PM
Go to Top of Page

BennettS

6 Posts

Posted - 05/08/2018 :  06:17:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you for the hint, I got the script to do everything I wanted now.
The cell notation seems to be more forgiving in regards to a variable input than col()[] and csetvalue can apparently be used to put a string into a cell when directly assigning it does not work. Well, things learned...

For reference, the working code:

//Part 1
newbook name:="Fit" sheet:=1 option:=lsname chkname:=1;
range rWfit = [Fit]Sheet1!;
rWfit.nCols = rWfit.nCols + 14;
col(A)[L]$ = Kommentar;
col(B)[L]$ = A1;
col(C)[L]$ = A2;
col(D)[L]$ = A3;
col(E)[L]$ = w1;
col(F)[L]$ = w2;
col(G)[L]$ = w3;
col(H)[L]$ = f1;
col(I)[L]$ = f2;
col(J)[L]$ = f3;
col(K)[L]$ = A1rel;
col(L)[L]$ = A2rel;
col(M)[L]$ = A3rel;
col(N)[L]$ = att1;
col(O)[L]$ = att2;
col(P)[L]$ = att3;
csetvalue col:=col(K) formula:="Col("A1")/(Col("A1")+Col("A2")+Col("A3"))" recalculate:=1;
csetvalue col:=col(L) formula:="Col("A2")/(Col("A1")+Col("A2")+Col("A3"))" recalculate:=1;
csetvalue col:=col(M) formula:="Col("A3")/(Col("A1")+Col("A2")+Col("A3"))" recalculate:=1;
csetvalue col:=col(N) formula:="Col("w1")/Col("A1")" recalculate:=1;
csetvalue col:=col(O) formula:="Col("w2")/Col("A2")" recalculate:=1;
csetvalue col:=col(P) formula:="Col("w3")/Col("A3")" recalculate:=1;

//part 2
page.active = 1;

csetvalue col:=col(A)[1001:10000] formula:="col(a)[1000]+((i-1000)*(col(a)[1000]-col(a)[999]))";
csetvalue col:=col(B)[1001:10000] formula:="0";

fft1 col(B) win:=hanning re:=0 im:=0 ap:=0 ri:=0 db:=0 psd:=0;


string comment$="Kommentar";
int ii = 1;
getn (Comment) comment$
(Index) ii;
range cc = 1!col(B);
cc.Comment$ = comment$;


page.active$ = "FFTResultData1";
plotxy (1,2) plot:=200;
nlbegin 1 func:=Lorentz_3 nltree:=ParamTree;
nlfit;
nlend 1 2;



csetvalue col:=[Fit]Sheet1!col(A)[ii] formula:="comment$";
[Fit]Sheet1!Cell($(ii),2) = ParamTree.A1;
[Fit]Sheet1!Cell($(ii),3) = ParamTree.A2;
[Fit]Sheet1!Cell($(ii),4) = ParamTree.A3;
[Fit]Sheet1!Cell($(ii),5) = ParamTree.w1;
[Fit]Sheet1!Cell($(ii),6) = ParamTree.w2;
[Fit]Sheet1!Cell($(ii),7) = ParamTree.w3;
[Fit]Sheet1!Cell($(ii),8) = ParamTree.f1;
[Fit]Sheet1!Cell($(ii),9) = ParamTree.f2;
[Fit]Sheet1!Cell($(ii),10) = ParamTree.f3;
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