Author |
Topic  |
|
carat64
USA
Posts |
Posted - 11/19/2004 : 11:54:52 AM
|
Origin Version (Select Help-->About Origin): 6.0 Operating System: Windows XP
HI,
I have a large number of spectra files in ASCII format, one x column and one y column. I have imported >400 into an Origins worksheet and now I need to subtract one file from all of them and plot the resulting difference spectra. HOwever, each data file was imported as two columns in the worksheet (same 'x' column for each file) and in order to make a graph I need to delete every other column because they are labeled 'Y' in the worksheet. Is there an easy way to do this using a script?
Thanks, Cara |
|
Mike Buess
USA
3037 Posts |
Posted - 11/19/2004 : 3:05:36 PM
|
Hi Cara,
This might not be the slickest way but should work. Paste the following lines to the script window. Then activate the worksheet, select the entire script and press Enter.
%Z=""; for(i=3;i<wks.ncols;i+=2) { %A=wks.col$(i).name$; %Z=%Z %A; }; for(i=1;i>0;i++) { %A=%[%Z,#i]; if(%A=="") break; del col(%A); };
Mike Buess Origin WebRing Member |
 |
|
carat64
USA
Posts |
Posted - 11/20/2004 : 10:26:28 AM
|
Hi Mike,
Thanks, that does work. I have another question though: Now my data is in the format: X Y1 Y2 Y3 Y4... I want to subtract Y1 from all of the other Y columns. Then, I need to extract all of the values in a particular row of this worksheet and place it in a new worksheet as a column. A few weeks ago, Easwar responded to my question about the row extraction and wrote the following code to do this:
// Save name of active sheet to variable %a
%a = %h;
// Get number of columns in active sheet;
icols = %a!wks.ncols;
if( icols < 2 ) return;
//
// Create a new worksheet
win -t;
// Loop over all columns of source worksheet...
irow = 1;
for( ii = 2; ii <= icols; ii++ )
{
// Get label string of current column from source wks
%b = %a!wks.col$( ii ).label$;
// Place label in 1st col of new wks
%( %h, 1, irow ) = %b;
// Place value from "100th" row of source wks into 2nd column of new wks
%( %h, 2, irow ) = %( %a, ii, 100 ); // change 100 to desired row number of source sheet
// Look in LabTalk help files on how to pass row num as argument to an OGS section
irow++;
}
The row extraction code worked, except now, with this large data set of 400+ columns, only 30 values are extracted and placed into a new worksheet.(?) (the last value extracted is from column AP2, but the last column in the worksheet is SQ2.)
So my question is: how do you subtract the Y1 column from all others, and do you have any idea why the row extraction code doesn't work anymore?
thanks, Cara |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 11/20/2004 : 12:40:02 PM
|
quote: how do you subtract the Y1 column from all others?
After you've eliminated the extraneous X columns run this script on the resulting worksheet...
loop (i,3,wks.ncols) { %(%H,i)-=%(%H,2); };
quote: do you have any idea why the row extraction code doesn't work anymore?
A worksheet created with the win -t command has only 30 rows. You need to add the necessary number of rows...
%a = %h; icols = %a!wks.ncols; // Get number of columns in active sheet; if( icols < 2 ) return; win -t; set %H -er icols-1; // Create necessary rows in new worksheet // Remaining script is unchanged
Mike Buess Origin WebRing Member |
 |
|
carat64
USA
Posts |
Posted - 11/20/2004 : 7:10:31 PM
|
Hi,
Thank you again! I have found, however, that the script code that deletes every other column does not work for the entire worksheet. The last column that is deleted is: EC1. all of the '1' columns after this are still in the worksheet. Does the script you wrote have a limitation of only ~104 ?
Ok, and since I still have your attention, I have one more question: Now that the data is processed to this point: XYYYYYY..., For a particular wavelength (a row value) I would like to 'align' all of the spectra (columns) to be at zero. However, for each column the value that needs to be subtracted from all of the values in that column, is different. Do you know how to write a script to do that? I think it would be something like this: (except in the language that the program understands...)
For a particular row (variable that can be changed), get the value for that column and subtract it from every value in that column, then go to the next column (i+1) and for the same row (defined above), get the value in that column & row (new/different) and subtract it from every value in that column (i+1). This is making a linear correction for small drifts in the baseline of the spectra if they drift over time.
Thank you for your help!
Cara |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 11/21/2004 : 09:49:35 AM
|
Hi Cara
I don't know why the script fails for high column numbers but I verified that it does in Origin 6.0. However, this simpler script seems to work...
for(i=2;i>0;i++) { if(i==wks.ncols) break; del wcol(i+1); };
The following script should work if I understand your problem correctly. It subtracts the value in row ii (defined in first line of script) of column i from all values in column i.
ii = 1; // row number loop (i,2,wks.ncols) { cc = wcol(i)[ii]; wcol(i) -= cc; };
Mike Buess Origin WebRing Member |
 |
|
carat64
USA
Posts |
Posted - 11/21/2004 : 1:27:04 PM
|
Thank you! All of the scripts work. This is a huge help!
Cara |
 |
|
|
Topic  |
|
|
|