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
 Origin Forum
 Row multiplication
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

zango24

India
Posts

Posted - 09/20/2017 :  1:09:05 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8
Operating System: 7

Dear Friends,
I need your help in the following calculation. I have a worksheet with X and Y column values. These columns contain several rows. E.g.
S. X Y
1 20 12
2 02 07
3 31 48
4 11 18
5 19 07
6 53 25
. . .


So, Now I would like to multiply row 1 of X to row 2 of X, then row 2 of X to row 3 of X, then row 3 of X to row 4 of X... and so on in a continuous fashion. Similar multiplication for Y rows too as row Y1*Y2 then Y2*Y3 then Y3*Y4 and so on.....

Actually, this type of calculation is required as a part of vector multiplication serise.
Any small worksheet script or method to execute this serise of multiplication would be a great help.
Thanks in advance,
Zan

nick_n

Finland
125 Posts

Posted - 09/20/2017 :  4:15:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Try to run that script in Script Window (to open Alt+Shift+3):
X data should be in column 1 and Y in column 2.

int ii;

loop(ii, 1, wks.maxrows)
{
if (col(1)[ii+1]==NA || col(2)[ii+1]==NA) break; //check if data
col("MultipX")[ii+1]=col(1)[ii]*col(1)[ii+1]; //output X
col("MultipY")[ii+1]=col(2)[ii]*col(2)[ii+1]; //output Y
}

Best regards,

Nikolay
Go to Top of Page

snowli

USA
1386 Posts

Posted - 09/20/2017 :  4:43:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can use Set Column Value dialog for this but Origin 8 needs to use col(A) instead column shortname directly.

E.g. Here is how to do it in Origin 2017.


Thanks, Snow
Go to Top of Page

zango24

India
Posts

Posted - 09/20/2017 :  10:56:27 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear Friend Nick_n,
Thank you for your help. I have checked its working like a charm. In fact, I have also checked by changing the column 1 or 2 to column 2 and 3 and its worked fine. I changed it because the first column of my data sheet contains serial number.
Now the new script would be:

int ii;
loop(ii, 1, wks.maxrows)
{
if (col(2)[ii+1]==NA || col(3)[ii+1]==NA) break; //check if data
col("MultipX")[ii+1]=col(2)[ii]*col(2)[ii+1]; //output X
col("MultipY")[ii+1]=col(3)[ii]*col(3)[ii+1]; //output Y
}

Cheers,
Zan



quote:
Originally posted by nick_n

Hi,

Try to run that script in Script Window (to open Alt+Shift+3):
X data should be in column 1 and Y in column 2.

int ii;

loop(ii, 1, wks.maxrows)
{
if (col(1)[ii+1]==NA || col(2)[ii+1]==NA) break; //check if data
col("MultipX")[ii+1]=col(1)[ii]*col(1)[ii+1]; //output X
col("MultipY")[ii+1]=col(2)[ii]*col(2)[ii+1]; //output Y
}

Best regards,

Nikolay

Go to Top of Page

zango24

India
Posts

Posted - 09/20/2017 :  11:02:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear Friend Snowli,
Thank you for your help. I have also checked this in my version 8 and its working like a charm too.
However, I have to do some modification may be due to the difference in the origin versions between yours and mine.

Instead of just taking B*B[i+1] in the "set column value", I have to use: col(B)[i]*col(B)[i+1] as suggested by you.

Thank you for your suggestions and help.
Cheers,
Zan


quote:
[i]Originally posted by snowli


You can use Set Column Value dialog for this but Origin 8 needs to use col(A) instead column shortname directly.

E.g. Here is how to do it in Origin 2017.


Thanks, Snow

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