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 for Programming
 LabTalk Forum
 Averaging X cells of different columns on a sheet

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
onoseque Posted - 12/28/2020 : 03:57:51 AM
Origin Ver. 2021 Student Version
Operating System: Windows

Hi and sorry if I'm asking too basic stuff but I am just starting with coding.
I have a sheet resulting of unstacking batch peak analyzing. Every 8 columns corresponds to 1 data set (total number of columns in the sheet 184).
I want to average every 5 cells of the second column (of every 8 column serie). So I use

wks.addCol(Result);
col(Result)=ave(col(b),5);
col(Result)[L]$ = Peak1;
col(Result)[U]$ = Area;

And this works for the first column. My problems:
1) I am reading about the looping over columns but don't succeed in making it repeat the same operation on the second column of every 8th.
2) Making manual tests in changing the column the script rewrites the results in the same "Results" Column. So it creates a new "Result1" col but writes the data into the the previous "Result" column. I am aware that this must be a very basic issue to create a new result column on every run. The long name should of course also change (Peak 1, 2 etc etc)
3) I need to do the exact same operation but obtaining the standard deviation instead of the average. I have tried
col(Error)=double StdDev(col(b),5);
but it doesn't work. Any tip?

Thank you so much
6   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 12/30/2020 : 05:18:21 AM
Yes anything that is actually programming in Origin it is better to go with Python, as we will continue to improve Python support with the originpro package.

If you are already familiar with programming in Labtalk, make sense to continue, but otherwise, then Python is the way going forward.

CP
onoseque Posted - 12/30/2020 : 02:17:25 AM
Hi James, thanks! It worked perfect. So I guess at this point, it doesn't make sense to learn LabTalk any more?
Thanks again and cheers
YimingChen Posted - 12/29/2020 : 1:07:38 PM
Hi,

In Origin 2021, you can also use Python script for such. Select from menu Connectivity:Open Untitiled.py..., put in the following script in the Code Builder window, and hit F5 to run.

import numpy as np
import originpro as op
 
wks = op.find_sheet()
nn = wks.cols

wks1 = op.new_sheet()
wks1.cols = 0

for i, idx in enumerate(range(1, nn, 9)):  # loop over second col of every 9 columns
    data = np.asarray(wks.to_list(idx))
    nc = len(data) // 5
    data = np.split(data[:5*nc],nc)
    wks1.from_list(wks1.cols, np.mean(data,1), f"Peak{i+1}", 'Area')
    wks1.from_list(wks1.cols, np.std(data,1), f"Peak{i+1}", 'Error')


James
YimingChen Posted - 12/29/2020 : 12:18:17 PM
Hi,

1. You can refer to the newly added column by index, so the index of last column is the wks.ncols, which is the counts of columns.
2. We don't have group stddev function and will add it. For now you may calculate the group stddev with formula sqrt((E(X^2) - E(X)^2))

Please try the script below:

wks.addCol();
wcol(wks.ncols)[L]$ = Peak1;  // wks.ncols gives the index of last column
wcol(wks.ncols)[U]$ = Area;
wcol(wks.ncols)[O]$= "ave(B,5)";

wks.addCol();
wcol(wks.ncols)[L]$ = Peak1;
wcol(wks.ncols)[U]$ = Error;
wcol(wks.ncols)[O]$= "sqrt((ave(B^2,5) - ave(B,5)^2))"; // std = sqrt((E(X^2) - E(X)^2))


James
onoseque Posted - 12/29/2020 : 03:27:20 AM
Hi! thanks for your message. Yes, I was going for the ave function. It is not the moving average what I want, but the average of fixed groups (so row 1-5, row 6-10 etc) and the sample standard deviation of the same groups. Then repeat the process for every 2nd of every 9 columns
cpyang Posted - 12/28/2020 : 11:13:30 AM
You are using ave function? How about the X value? Is using moving average ok? Using moving average will allow the original X column to be used. I assume you will need to plot the result and thus the correct X values will be needed?

CP

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