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
 Sum (summation from row N to row M)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

qwertqqq

12 Posts

Posted - 01/22/2009 :  12:26:24 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
/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!

cpyang

USA
1406 Posts

Posted - 01/22/2009 :  9:27:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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


Go to Top of Page

qwertqqq

12 Posts

Posted - 01/23/2009 :  03:50:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

greg

USA
1378 Posts

Posted - 01/23/2009 :  09:15:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page

qwertqqq

12 Posts

Posted - 01/23/2009 :  10:51:06 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I see. Thank you
Go to Top of Page

memph

Denmark
2 Posts

Posted - 08/17/2009 :  09:47:57 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
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