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
 set column values - sum block of numbers vector
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Tiago Moraes

Brazil
3 Posts

Posted - 06/09/2020 :  10:23:47 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,
I have a col(A) and I want to create a col(B) using Set Column Values, where each number in Col(B) is the sum of each 10 numbers in Col(A).

Col(A) | Col(B)
1 | sum(col(A)[1:10])
2 | sum(col(A)[11:20])
3 | sum(col(A)[21:30])
... |

I think there is a simple code for it. But I am not getting it.
Can anyone help me?
Thank you,

Origin 9
Operating System: Windows 7

--
Tiago

YimingChen

1630 Posts

Posted - 06/09/2020 :  1:41:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try set column value with formula: total(col(A)[10*(i-1)+1:10*i])

James
Go to Top of Page

Tiago Moraes

Brazil
3 Posts

Posted - 06/09/2020 :  2:39:50 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

Try set column value with formula: total(col(A)[10*(i-1)+1:10*i])

James



Hi James, it does not work.

Set Column Values does not understand the sum index from [10*(i-1)+1] to [10*i] using colon :
thank you,

--
Tiago
Go to Top of Page

YimingChen

1630 Posts

Posted - 06/09/2020 :  3:16:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
That is because your Origin version is too old. Try this way, go to menu Window->Script window. Paste the following script, highlight all and press enter key to run.

n = int(wks.nrows/10);
range r2 = col(B);
for (int i = 1; i <= n; i++)
{
	range r1 = Col(A)[10*i-9:10*i];
	r2[i] = total(r1);
}


James
Go to Top of Page

Tiago Moraes

Brazil
3 Posts

Posted - 06/10/2020 :  07:36:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by YimingChen

That is because your Origin version is too old. Try this way, go to menu Window->Script window. Paste the following script, highlight all and press enter key to run.

n = int(wks.nrows/10);
range r2 = col(B);
for (int i = 1; i <= n; i++)
{
	range r1 = Col(A)[10*i-9:10*i];
	r2[i] = total(r1);
}


James



Great! It works!
Thank you very much!

--
Tiago
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