Author |
Topic  |
|
razva
Germany
Posts |
Posted - 09/27/2005 : 3:47:06 PM
|
Origin Version 7.5: Operating System:WinXP SP2
I have about 1000 files to process and I cannot do it manually as it is time consuming. The operations I need are simple but I don't know how to make the script.
I have some data and I need to extract a line which shoul be a fit of a portion of my curve and I want the result in a new column on the same worksheet. So I need a script to make a linear fit in an interval and then the function to be substracted from my data.
Can anybody help me? Thankx |
|
Thomas M
Germany
Posts |
Posted - 09/28/2005 : 08:46:37 AM
|
Do you start always at the same row, or at the same value? Does your fit always have the same length or does it differ? Where does it end? After 100 rows or at a special value? Can you give an example?
With result i guess you mean the equation of the linear regression, right? |
 |
|
razva
Germany
Posts |
Posted - 09/28/2005 : 12:46:32 PM
|
I always start on the same row and end after about 20 values. In fact I have the same X column for all the datasheets. I have some hundreds points and I only need a linear fit for the first 20 let's say. I need the equation corresponding to the linear regression to be inserted in a new column of the same sheet (the column should be automatically created)so I will be able to use it in "set column values". Then the script should substract this new column from the initial Y column I had (all hundreds points, not only first 20).
|
 |
|
razva
Germany
Posts |
Posted - 09/29/2005 : 3:59:58 PM
|
I have now a script which makes linear fit and writes in the worksheet the values I needed. I still have problems making the script to run for all datasheets I have. Any suggestions? |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 09/29/2005 : 5:16:17 PM
|
As long as your script acts on the active worksheet you can apply it to all worksheets in the project with the document -e command...
doc -e W { // your script goes here };
Mike Buess Origin WebRing Member |
 |
|
razva
Germany
Posts |
Posted - 09/30/2005 : 11:32:34 AM
|
It will be good to work but it is not so yet. The problem is that I used lr data1_b and I have to modify the dataset name to generalize and make it of the form data*_b with a wildcard. I do not know yet how to do it. |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 09/30/2005 : 11:43:53 AM
|
The string variable %H always holds the name of the active window so you can use lr %H_b. Alternatively, lr col(b) will probably work.
Mike Buess Origin WebRing Member |
 |
|
razva
Germany
Posts |
Posted - 10/07/2005 : 07:24:07 AM
|
It works perfectly for projects with few worksheets. I needed the script for large projects, with more than 500 worksheets. It keeps telling me "#command error!"
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/07/2005 : 07:32:48 AM
|
What is 'it'? What script are you using?
Mike Buess Origin WebRing Member |
 |
|
razva
Germany
Posts |
Posted - 10/07/2005 : 09:08:20 AM
|
the script is like it follows:
doc -e W { lr %H_b -b 1 -e 61; type slope is $(lr.b); type intercept is $(lr.a); aa=lr.a; //rename the fit parameters bb=lr.b; //rename the fit parameters win -a %H; //this will set "data(n)" as active window wo -c linear; //this is the comand for creating a new column called "linear" in the active window col(5)=aa + bb*col(1); wo -c substracted; col(6)=col(2)-col(5); };
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/07/2005 : 10:10:43 AM
|
I think the only line in your script that can generate a command error is lr %H_b -b 1 -e 61; and that will happen if the wks does not have a column B. You can test that with the following script...
doc -e W { %W=%H; type %W; lr %H_b -b 1 -e 61; //type slope is $(lr.b); //type intercept is $(lr.a); aa=lr.a; //rename the fit parameters bb=lr.b; //rename the fit parameters //win -a %H; //this will set "data(n)" as active window - %H is already active wo -c linear; //this is the comand for creating a new column called "linear" in the active window col(5)=aa + bb*col(1); wo -c substracted; col(6)=col(2)-col(5); };
The script types the name of each wks to the script window. The wks that caused the command error is saved as %W and can activated with win -a %W. If the wks has no col B you need to modify your script to handle such exceptions. If it has a col B you can apply the script inside the doc -e brackets to that wks separately to determine why the lr command fails.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 10/07/2005 10:13:45 AM |
 |
|
razva
Germany
Posts |
Posted - 10/07/2005 : 10:50:13 AM
|
you are perfectly right. i have tested on a smaler data system and it worked fine. when I had to try on my real data, I did not have column B but a renamed column "capacitance". I have modified it in the script which starts to run but it gives me an error when it reaches the 9th worksheet. maybe there are to many worksheets? thanks for your help |
 |
|
razva
Germany
Posts |
Posted - 10/07/2005 : 10:52:23 AM
|
it goes like this
doc -e W { lr %H_Capacitance -b 1 -e 61; type slope is $(lr.b); type intercept is $(lr.a); aa=lr.a; //rename the fit parameters bb=lr.b; //rename the fit parameters win -a %H; //this will set "data(n)" as active window wo -c linear; //this is the comand for creating a new column called "linear" in the active window col(5)=aa + bb*col(1); wo -c substracted; col(6)=col(2)-col(5); }; slope is 2,83538E-13 intercept is 5,20029E-11 slope is 2,8012E-13 intercept is 5,20179E-11 slope is 2,80503E-13 intercept is 5,20064E-11 slope is 2,82762E-13 intercept is 5,2004E-11 slope is 2,8131E-13 intercept is 5,19938E-11 slope is 2,96109E-13 intercept is 5,20274E-11 slope is 2,81242E-13 intercept is 5,19981E-11 slope is 2,82593E-13 intercept is 5,20071E-11 slope is 2,78983E-13 intercept is 5,2002E-11 #Command Error! |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/07/2005 : 11:38:51 AM
|
Use the test I suggested above to find out what's wrong with the offending wks. You can also avoid the column name issue entirely by using lr col(2) -b 1 -e 61.
A few more hints... Very large projects are prone to corruption so you should avoid unnecessary datasets (columns). Unless you really need the line column you should reuse it with col(5) = col(2) - col(5). You can save the slope and intercept in the column label for future reference. Also, it's not necessary to save lr.a and lr.b as aa and bb. They can be used directly in your column formula. Finally, win -a %H is not needed... it activates the already active worksheet. It probably doesn't harm the script but you can avoid some flickering of window titles by leaving it out.
Please try the following script. If you still get a command error use win -a %W to look at the offending wks. You can reinstate col(6) and your own column names later if you wish.
doc -e W { %W=%H; lr col(2) -b 1 -e 61; %L=a: $(lr.a) b: $(lr.b); // no ';' on previous line wo -c diff; wks.col5.label$=%L; // add intercept & slope to column label wks.labels(); // show column labels col(5)=lr.a + lr.b*col(1); col(5)=col(2)-col(5); };
...If you are importing your data with File > Import Multiple ASCII the wks is named after the data file by default which can create rather long wks names. The wksName_colName string is limited to 23 characters so the name of your Capacitance column might be truncated in some worksheets. That could account for your latest command error and using col(2) in place of %H_Capacitance should fix it.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 10/07/2005 12:06:37 PM |
 |
|
razva
Germany
Posts |
Posted - 10/07/2005 : 3:40:57 PM
|
mille grazia! thanks a lot. I will try to run your script. meanwhile I used rename option in total commander to modify the names of the worksheets. the problem was solved somehow, as it was all about truncating the name of the worksheets. there were processed the first 9 of the datasets as the 10th had one more character in the name and was after truncation not recognised. I will test the script and post new comments or ask other things related to it. your support was keeping me advance |
 |
|
|
Topic  |
|