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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 simultaneous column maths
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

coll@inia.

Spain
125 Posts

Posted - 06/13/2004 :  12:32:13 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I would like to transform several columns of raw data in a worksheet simultaneoulsly.
A very common situation is substract a background value to all the data and/or to transform every data in several columns to normalize them and compare data with other experiments.
I can do that in every column one by one but it is time consuming and prone to errors. I can also do it by using the Tools/worksheet script, but I have to type the values for each data1_B,C,D,E,.. and so on.
I would like to have the script to be executed with a bottom after filling out a formula with the background values and constant values for that particular experiment. Then upon clicking in the bottom all the columns will be transformed by the formula, for instance (data1_B,C,D,E,.. - background) / constant1 * constant2.
Is there any possibilities to or an script to do that?
Thank you for your help, Dr.Coll

Mike Buess

USA
3037 Posts

Posted - 06/13/2004 :  4:00:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
There are many ways to do that but it would be difficult to incorporate an arbitrary formula into a script. If you just have a few possible formulae you could attach the following script to the Custom Routine or any other button. The script has an option for applying the formula to all Y columns (which I suspect you really want to do). If that's not what your want just enter a space-separated column list in the appropriate field.
%L=B C D E F;
i1=1; i2=0; i3=1
getn (background) background
(1st constant) constant1
(2nd constant) constant2
(formula #) i1;
(apply to all Y columns) i2:2h
(apply to these columns) %%L
(Enter choices);
%Z="";
if(i2) {
for(i=1;i<=wks.ncols;i++) {
if(wks.col$(i).type==1) {%A=wks.col$(i).name$; %Z=%Z %A};
};
};
else %Z=%L;
for(i=1;i>0;i++) {
%A=%[%Z,#i]; if(%A=="") break;
switch(i1) {
case 1:
%H_%A-=background;
%H_%A*=constant2/constant1;
break;
case 2:
- formula 2 commands -
break;
case 3:
- formula 3 commands -
break;
- more formulae -
};
};


Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 06/14/2004 08:23:35 AM
Go to Top of Page

coll@inia.

Spain
125 Posts

Posted - 06/24/2004 :  03:56:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Mike for your reply.
Based on what you sent me I developed the following script:

//initialize variables
back=0;
div=1;
factor=1;

//show getnumber input window
getn (- back) back
(/ div) div
(* factor) factor
(restar back, dividir por div, multiplicar x factor);

//apply formula to selected columns
sel1=wks.c1;
sel2=wks.c2;

for(i=sel1;i<=sel2;i++) if(wks.iscolsel(i)!=0){%D=wks.col$(i).name$;
%H_%D-=back;
%H_%D/=div;
%H_%D*=factor}

It seems to work fine for whole columns and single columns, however I found out that when many columns are not completely selected (only a few rows), the script still calculates the values for the whole columns!.
It seems likely that I have to introduce in the script some information about the selected rows [i]. Could you please indicate me what changes in the above mentioned script are necesary to do that? In other words, I will need that the +, -, / or * operators will be applied not only to the columns selected but also and only to the selected rows of those columns.
Yhank you for your help, bye now, Dr.Coll
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 06/24/2004 :  08:34:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
In that case you need to address each cell individually which is much less efficient than operating on entire columns. I'd provide for both possibilities...

for(i=wks.c1;i<=wks.c2;i++) {
# Skip col if it has no selections
if(wks.isColSel(i)==0) continue;
# If entire col selected use vector math
if(wks.isColSel(i)==1) {%(%H,i)-=back; %(%H,i)/=div; %(%H,i)*=fac};
else {
for(j=wks.r1;j<=wks.r2;j++) {%(%H,i,j)-=back; %(%H,i,j)/=div; %(%H,i,j)*=fac};
};
};

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 06/24/2004 09:03:14 AM
Go to Top of Page

coll@inia.

Spain
125 Posts

Posted - 06/25/2004 :  01:26:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Mike!, it works fine and it is simpler than my script! thank you again, julio
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000