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
 Sum (summation from row N to row M)

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
qwertqqq Posted - 01/22/2009 : 12:26:24 PM
/OriginPro 8, Win XP/

Hello,

I can see that there is an intrinsic function Sum, which computes the sum of the first elements in a column, from row 1 to row i. Is there also an intrinsic function to compute the sum of the elements starting from row N to row M? If there is no such an intrinsic function, how to create it without going deep into programming?

Thank you!
5   L A T E S T    R E P L I E S    (Newest First)
memph Posted - 08/17/2009 : 09:47:57 AM
quote:
Originally posted by greg

The upper (old) part of the Set Column Values dialog only accepts an expression that returns a value as it loops over the row range designated by 'From' and 'To'.
The lower (new in Origin 8) part of the dialog - 'Before Formula Scripts' - can run anything you care to code and in some cases may be the only part of the dialog you will use.

It's not clear what you are trying to accomplish in Set Column Values, but here is an example that finds the mean of every four rows of values in column 1 and places the results in column 2 :

dataset ds1;
ds1 = col(1);
Size = ds1.GetSize();
BlockSize = 4;
range rd2 = col(2); // target column
for(RowIndex = 1; RowIndex < Size; RowIndex += BlockSize)
{
range rd1 = col(1)[$(RowIndex):$(RowIndex+BlockSize-1)];
sum(rd1);
rd2[1+(RowIndex-1)/BlockSize] = sum.mean;
}

The entire script resides in the "Before Formula Script" section and the expression section is empty.




Hi Greg

I need to find the mean of 5 numbers in col(1) and put the result in col(2), row(1). Then find the mean of the next 5 numbers in col(1) and place the result in col(2), row(2). I tried your method, but I can't make it work. If I don't put anything in th expression section, nothing is happening.

Also I need to take the deviation from the mean and put in col(3).

Do you if this is possible?

Thanks, Kaola
qwertqqq Posted - 01/23/2009 : 10:51:06 AM
I see. Thank you
greg Posted - 01/23/2009 : 09:15:04 AM
The upper (old) part of the Set Column Values dialog only accepts an expression that returns a value as it loops over the row range designated by 'From' and 'To'.
The lower (new in Origin 8) part of the dialog - 'Before Formula Scripts' - can run anything you care to code and in some cases may be the only part of the dialog you will use.

It's not clear what you are trying to accomplish in Set Column Values, but here is an example that finds the mean of every four rows of values in column 1 and places the results in column 2 :

dataset ds1;
ds1 = col(1);
Size = ds1.GetSize();
BlockSize = 4;
range rd2 = col(2); // target column
for(RowIndex = 1; RowIndex < Size; RowIndex += BlockSize)
{
range rd1 = col(1)[$(RowIndex):$(RowIndex+BlockSize-1)];
sum(rd1);
rd2[1+(RowIndex-1)/BlockSize] = sum.mean;
}

The entire script resides in the "Before Formula Script" section and the expression section is empty.
qwertqqq Posted - 01/23/2009 : 03:50:54 AM
quote:
Originally posted by cpyang

You can declare a range variable with the specified rows and use sum, like


int i1 = 2;
int i2 = 6;
range a=col(a)[$(i1):$(i2)];
sum(a);
sum.min=;
sum.N=;

thanks.

However, I just need to change one worksheet column through the "set column values" dialog. I guess it would be difficult to implement the function that you suggested in this dialog.
cpyang Posted - 01/22/2009 : 9:27:19 PM
You can declare a range variable with the specified rows and use sum, like


int i1 = 2;
int i2 = 6;
range a=col(a)[$(i1):$(i2)];
sum(a);
sum.min=;
sum.N=;


CP



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