T O P I C R E V I E W |
Vincentrou |
Posted - 08/05/2004 : 04:23:54 AM Hello (sorry for my english) here is my problem : I work in an optic lab and want to analyse somes datas which are in a worksheet. The colums are CH0, errorCH0, CH1, errorCH1, CH2,...and frequencies. In the column frequencies, some values are "0" because there is an offset that I measure in those lines. I want to create a program which : - find the lines with "0" as value of the frequency - make the mean of thoses lines for the columns CH0, CH1, CH2... - subtract this mean to the colums CH0, CH1, CH2... (but not to the columns calles "errorCHi")
Sorry if it's not very comprehensible! Maybe somebody have ideas to create this program because I'm a dummy in programming! Thank you. |
5 L A T E S T R E P L I E S (Newest First) |
Vincentrou |
Posted - 08/06/2004 : 05:27:47 AM Thank you. It works perfectly ! |
easwar |
Posted - 08/05/2004 : 5:38:08 PM Hi,
The following LabTalk script code will, I think, do what you want. I am assuming that you have many columns such as Ch0, ErrCh0, Ch1, ErrCh1...etc and then one last column that has Freq.
To run this code, make the worksheet active, copy and paste to script window, highlight/select the entire code, and hit Enter key. You can then assign this code to a button, such as the Custom Routine button - see help file on how to create and use buttons.
Please verify the computation to make sure the subtraction is done the way you wanted.
Easwar OriginLab
ncols = wks.ncols; // get number of columns in wks create mytemp -n ncols; // create temp dataset for computing average offset set mytemp -e ncols; // set temp dataset limit mytemp = 0; // clear temp dataset noff = 0; // counter for how many rows have offset info for( ii = 1; ii <= wks.nrows; ii++ ) // loop over all rows of worksheet { if( 0 == %( %h, ncols, ii ) ) // if last column has 0, this row is offset line... { noff++; // update offset row counter for( jj = 1; jj < ncols - 1; jj += 2 ) // loop over all odd columns in this row { mytemp[ jj ] = mytemp[ jj ] + %( %h, jj, ii ); // add to temp dataset }; }; }; if( 0 == noff ) return; // if no offset rows found, quit mytemp /= noff; // average temp dataset for( jj = 1; jj < ncols - 1; jj += 2 ) // loop over all odd columns and subtract averaged offset { %( %h, jj ) -= mytemp[ jj ]; } delete mytemp; // delete temp dataset
|
Mike |
Posted - 08/05/2004 : 1:10:30 PM If you were willing to do this through the user interface, you could complete the third step using the Set Column Values feature (by which you could create a data set using some variation on your "col(CHi)=col(CHi)- mean of the offsets of CHi" expression).
You might try posting on the LabTalk forum. Perhaps some generous soul will help you automate this.
Mike OriginLab |
Vincentrou |
Posted - 08/05/2004 : 11:59:46 AM Thank you for those tips because I am a beginner! But in fact, I prefer to do all the actions in one program because there are many many worksheets to be analysed so it would be better if I had just one button to push.
The third action is : col(CHi)=col(CHi)- mean of the offsets of CHi. |
Mike |
Posted - 08/05/2004 : 09:43:37 AM Hi Vincentrou:
You may be able to do this without any programming; I'm not certain because I don't quite understand your third step.
To extract rows of values with "0" values in the frequency column, use the Analysis: Extract Worksheet Data menu item (e.g. col(E)[i]==0).
To calculate the mean value of those extracted values, select a range of worksheet data and choose Statistics:Descriptive Statistics:Statistics on Columns.
Could you explain your third task further?
Mike OriginLab |
|
|