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