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
 All Forums
 Origin Forum
 Origin Forum
 Apply formula to multiple columns

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
leonardo.a027 Posted - 09/09/2016 : 02:12:35 AM
Hi!
I have been trying this for a long time now.
I have a lot of data in diferent workbooks in a folder. I have to multiply one column of each workbook by another column (reference column) then the result to be saved in a new column at each worksheet.
I need to make automatic for the workbooks because I have a lot of data, so doing it one a time is not an option.
I will really apreciate the help.
Thank!
P.D: I am using Origin 2016.
5   L A T E S T    R E P L I E S    (Newest First)
jmenges Posted - 09/11/2018 : 2:12:39 PM
Hello Pros,

I have a similar problem as leonardo. I have one sheet in my project with 400 xyxy columns and i want to do a two-dimensional frequency count for a single range of intensity values ( like 10000 to 20000 on x and 0 to 10000 on y) and only need the total count of data pairs in this regime. I tried these two variances in Origin 2018 Pro:
// Loop over all columns ...
// Restricted to the current Project Explorer Folder View
doc -ef W
{
loop(ii,1,wks.ncols)
{
range rA = [%H]sheet1!col(1);
range rB = [%H]sheet1!col(2);
range rR = [%H]sheet2!col($(newColIndex));
rR = (rA>10000)*(rA<20000) * (rB>0)*(rB<10000);
}
}
// Loop over all columns ...
// Restricted to the current Project Explorer Folder View
doc -ef W
{
int ncols = wks.ncols - 1;
loop(icol,1,wks.ncols)
for(int icol = 1; icol <= ncol; icol++)
{

range rA = [%H]sheet1!col($(icol));
range rB = [%H]sheet1!col($(icol+1));
range rR = [%H]sheet2!col($(icol));
rR = (rA>10000)*(rA<20000) * (rB>0)*(rB<10000);
}
}
but it´s not doing what i want yet only one column at a time and i would still need only half of the values bacause i need only the xy pair count... and further the total amount of every count.
As I am literally a newby in this field, I really would appreciate your help!!!
Thanks in advance,
jmenges

SingleMolecule

Edit: I found the first answer myself, thanks anyway
// Loop over all columns ...
// Restricted to the current Project Explorer Folder View
doc -ef W
{
for(icol = 2; icol <= wks.ncols; icol = icol + 2)
{
range rB = [Book1]sheet1!col($(icol));
range rA = [Book1]sheet1!col($(icol-1));
range rR = [Book1]sheet2!col($(icol / 2));
rR = (rA>10000)*(rA<20000) * (rB>0)*(rB<10000);
}
}
leonardo.a027 Posted - 09/09/2016 : 3:25:42 PM
Thanks a lot for the help!!
It works perfectly!
Problem solved!!
snowli Posted - 09/09/2016 : 2:43:40 PM
Hello,

You can run this

range reff=[book1]sheet1!A; //suppose this is where reference column is
doc -ef W
{
loop(ii,1,page.nlayers)
{
col(B)=col(B)*reff;
}
}


If you want to exclude calculation in reference book, you can lock the workbook, or simple highlight all data there and choose Format Cells. Check Disable Editing.

BTW, if the data are not imported into each sheet yet, you can choose File: Import: Import Multiple ASCII
In the dialog that opens, there is a Script section to choose what script to run after each import

You can add code such as
range reff=[book1]sheet1!A;
col(B)=col(B)*reff;

So after each import, the calculation is done on col(B)

Thanks, Snow
leonardo.a027 Posted - 09/09/2016 : 1:46:39 PM
Hi yuki.
Thanks a lot for the help. You almost got the idea. The only diference is that all comun(B) of the worksheets in the folder have to be multiplied by only one column of only one worksheet (the reference data). I can put the reference data in another folder if it helps somehow.
yuki_wu Posted - 09/09/2016 : 04:48:23 AM
Hi,

Not sure if I understand your question fully.

Let me take a simple example to illustrate:
There are some workbooks in a folder and some worksheets in every workbook. In each worksheet, there are three columns: col(A), col(B) and col(C).

Now we want to calculate col(A)*col(C) for every worksheets and put the result in a new created column col(D), we can run the scripts below in Script Window:

// Loop over all Workbooks ...
// Restricted to the current Project Explorer Folder View
doc -ef W 
{
   // Loop over all worksheets in each workbook
   loop(ii,1,page.nlayers) 
   {
      range rW = [%H]$(ii)!;
      rW.addCol(Result);
      newColIndex = rw.nCols;
      range rA = [%H]$(ii)!col(1);
      range rB = [%H]$(ii)!col(3);
      range rR = [%H]$(ii)!col($(newColIndex));
      rR = rA * rB;
   } 
}

If you want to know more about how to loop Origin object, you can refer to:
http://www.originlab.com/doc/LabTalk/guide/Looping-Over-objs

Or you can try X-function in this case:

doc -ef W
{
	doc -e LW
	{
		vmathtool -r 2 ix1:=1 operator:=mul operand:=data ix2:=3 ox:=<new>;
	}
}


More details about vmathtool can be found here:
http://www.originlab.com/doc/X-Function/ref/vmathtool

Hope it helps!

Regard,
Yuki
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000