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
 Origin Forum
 [solved]Change/Fix fit parameters in analyze templ

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
andankert Posted - 01/10/2014 : 09:52:35 AM
Origin Ver. and Service Release (Select Help-->About Origin): 9.1
Operating System: Windows 8

Hi,

I'm trying to use Origin in the background to perform a complicated nonlinear fit and then return the result to Labview. I managed to make a analyze template in origin doing the fitting and with the labview examples I managed the communication. Now I'm facing the problem that I want to change the initial parameters accordingly and even fix one. Some of the Labview templates use a Setting page where one can for example define the fitting function. Even so I cannot find how this was made, could it help me to predefine my initial parameters like I want?

Thanks!
André
8   L A T E S T    R E P L I E S    (Newest First)
Echo_Chu Posted - 01/16/2014 : 05:25:36 AM
Glad to know your problems is solved. Sorry that I misunderstood in my last post. I thought you were asking a method to trigger the recalculation as my 1st suggestion.

Anyway, if you met auto update problem with my 2nd suggestion, it may because the range(Upon Changes in Range) is not correctly set in the Worksheet Script dialog. There is no way in Labview to trigger the script to run in such a analysis template. And the fit should be triggered by the change in range as you set in the Worksheet Script dialog.

If you still have question on it, you can send your analysis template and user defined function to tech@originlab.com. We can look into it to see what happened.
andankert Posted - 01/16/2014 : 04:00:05 AM
Ok, I don't understand why, but I managed to solve it:

I sent first the initial values to Origin and then the data just before running. Somehow the first triggered a fit, even though there were no data, and then the second change didn't trigger it. By switching the 2 actions it's working now fine.

Thank you very much for your help again, it brought me a great leap forward !!!

André
andankert Posted - 01/16/2014 : 03:41:04 AM
Hi,

the first option only works if I make a template by hand, unless I miss something here. Since I call the nlfit from my worksheet script, I don't see how I could set this option. (but I agree: before I did it, and it always worked!)

The run command is imo identical to OArun.vi. But even if not, I replaced it with your last hint and it did the same for me: nothing.

Now I'm not sure if the last sentence was meant so that I run my whole Labtalk script from Labview and not as Worksheet script? That seems like another appoach again, which is rather unpleasant since the worksheet template does already exactly what I want, except it doesn't auto-update by Labview.

Do you have any other suggestions?

/André
Echo_Chu Posted - 01/16/2014 : 01:40:41 AM
It is best to set the recalculate mode as Auto in the analysis template like the example of nonlinear curve fit dialog



However, if you need to force the pending operation to update. you can also execute the labtalk script - "run -p au;"

Please look at the example for how to execute labtalk from Labview
andankert Posted - 01/15/2014 : 2:15:21 PM
Hi,

thank you, this seems I managed to get it working even with a self defined function. The workbook re-fits on changes in data or settings and outputs fitting parameters and even x-y columns of the fit function.

Now I get a Labview problem: OARun.vi does not trigger the workbook update as it does for analyze templates without Labtalk script (like your first suggestion). If I pause Labview, trigger an update in Origin and then continue, it works. How can I trigger this now?

André
Echo_Chu Posted - 01/13/2014 : 11:41:53 PM
Hi, André

If so, you can perform the nlfit session in Labtalk and save the labtalk scripts in the worksheet.

Here are the steps how I create such an example to be fit with the Gaussian function

1. Prepare a workbook with three sheets, source data are put in the 1st sheet, the initial values are put in the 2nd sheet and results will be put back in the 3rd sheet as images below



2. Active the 1st sheet, select Worksheet: Worksheet Script from the Origin menu. In the dialog, select Upon Changes in Range and fill A,B in the text box. Then enter the scripts below in the lower box

//init NLFit object 
//associate the NLFit internal tree with LabTalk tree named tt
nlbegin 1!2 gaussian tt;

//Read initial values of each parameter from the 2nd sheet.
range rinit_col = 2!2;
range rfix_col = 2!3;
tt.y0=rinit_col[1];
tt.f_y0 = rfix_col[1];
tt.xc=rinit_col[2];
tt.f_xc = rfix_col[2];
tt.w=rinit_col[3];
tt.f_w = rfix_col[3];
tt.A=rinit_col[4];
tt.f_A = rfix_col[4];

// start iterations
nlfit;

//Put value and SE of each parameter in the 3rd sheet.
range param_col = 3!2;
range paramse_col = 3!3;
param_col[1] = tt.y0;
param_col[2] = tt.xc;
param_col[3] = tt.w;
param_col[4] = tt.A;
param_col[5] = tt.adjr;

paramse_col[1] = tt.e_y0;
paramse_col[2] = tt.e_xc;
paramse_col[3] = tt.e_w;
paramse_col[4] = tt.e_A;

//End fitting process to clean up internal objects without generate report sheet
nlend;



3. Active the 2nd sheet and do the same. but this time the script will be perform upon changes in range "B, C"

Now any change in the source data in sheet1 or initial values in sheet 2 will make the script run and return values in sheet 3. Save the worksheet as an analysis template. Then you can send data from LabVIEW to sheet1 and sheet2, and receive the results from sheet3

You can also learn how to perform nonlinear session in labtalk from and modify the codes as you needs in the links below
http://www.originlab.com/doc/LabTalk/guide/Non-linear-Fitting
http://www.originlab.com/doc/X-Function/ref/nlbegin#Example

I will also send you the worksheet I created by email. Hope the solution helps this time.

Echo
OriginLab Crop.
andankert Posted - 01/13/2014 : 12:07:04 PM
Hi,

thanks for the reply. I tried it a little, and if I figured and understood you correctly, I cannot set a fixed initial value from Labview!? If so, I'll need to find another solution, since it's necessary for my fitting: each data set has a individual, but predefined parameter I need to set. If I could adjust it by Labview, it would make my life much easier.

/André
Echo_Chu Posted - 01/13/2014 : 04:03:20 AM
Hi, André

You can keep the initial values in a column in the sheet that contains the data, then change the param init code to read the values from that column, and then save the whole thing as template, and later change data or the init values in the worksheet from LabVIEW.

Let me take an example to show you how to address the worksheet column from parameter initial value of a user defined function. But you will need to manually set a fixed parameter value in your user-defined function.

1. Open Funciton Organizer by pressing F9
2. Expand Peak Functions branch, duplicate Gaussian function. Select the duplicated function.
3. Select the button next to the Parameter Settings dialog, fix A = 15 there.
4. Select User Labtalk radio box, which locates above the Parameter Initialization box
4. Empty the Parameter Initialization box and enter codes below


//example LT initial codes for user-defined gaussian function
//assume the sheet must be next to the source sheet, and the first column in the first four cells contains init params
range rpage=ry.getpage()$;
range rlayer=ry.getlayer()$;
int inext=rlayer.index+1;
range rpage rinit_col=$(inext)!1;
y0=rinit_col[1];
xc=rinit_col[2];
w=rinit_col[3];
//A=rinit_col[4];



Echo
OriginLab Corp.

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