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
 set column values - sum block of numbers vector

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
Tiago Moraes Posted - 06/09/2020 : 10:23:47 AM
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
4   L A T E S T    R E P L I E S    (Newest First)
Tiago Moraes Posted - 06/10/2020 : 07:36:05 AM
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
YimingChen Posted - 06/09/2020 : 3:16:21 PM
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
Tiago Moraes Posted - 06/09/2020 : 2:39:50 PM
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
YimingChen Posted - 06/09/2020 : 1:41:36 PM
Try set column value with formula: total(col(A)[10*(i-1)+1:10*i])

James

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