| Author |
Topic  |
|
|
consoli
Germany
Posts |
Posted - 06/19/2007 : 07:19:28 AM
|
Origin Version (Select Help-->About Origin): Origin Pro 7.5 SR6 Operating System: Windows XP
Hello forum members!
I'm new to this forum and not experienced with Origin C.
My problem:
I have multiple Worksheets in which colum 2 is X (time) and column 3 is Y (intensity). Averaging must be performed in every Worksheet in time intervals of 1 sec (Take intensitys from 0-1 sec, divide by number of values and save result, next 1-2 sec...).
Can you give me just an idea how to do this averaging for one worksheet, please? I don't know how to access each cell in a column in a proper way.
Thank you in advance,
Angelo Consoli
Edited by - consoli on 06/19/2007 07:22:21 AM
Edited by - consoli on 06/19/2007 07:23:57 AM |
|
|
Mike Buess
USA
3037 Posts |
|
|
consoli
Germany
Posts |
Posted - 06/19/2007 : 12:19:10 PM
|
Thank you for the answer.
Unfortunately I can't apply this solution.
I forgot to mention, that the interval between X-values (time) is not constant. So, I think I have to read every single value?
My biggest problem is I don't know how to access cells properly. An idea was to declare a dataset[col(x),col(y)], use a for loop to scan throug every cell in column x and an if-command (n sec < x < n+1 sec) to get a range for an interval. Then I can use this range to do the actual averaging in Y-values.
Does it make sense or ist to long winded?
Angelo Consoli
|
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 06/19/2007 : 3:07:03 PM
|
Hi Angelo,
quote: I forgot to mention, that the interval between X-values (time) is not constant. So, I think I have to read every single value?
Best if you can avoid reading all values. If the X column contains values that are exact multiples of 1.0 (sec) (say 0.0,1.0,2.0,3.0, etc.) you can use Data_list to find the index where a particular multiple of 1.0 sec occurs. Knowing the start and stop indices you can extract the subvector between start and stop and use Data_sum to obtain the mean. Example...
Worksheet wks = Project.ActiveLayer(); Dataset d1(wks,0); // assign dataset to first column int ii = Data_list(1.0, &d1, -1); // find 1st row containing 1.0 vector v1(d1),v2; v1.GetSubVector(v2,0,ii-1); // Create subvector from 0 to ii-1 Dataset d2(v2.GetSize()); d2 = v2; BasicStats bs; Data_sum(&d2,&bs); out_double("mean=",bs.mean); // mean between 0 and ii-1
If it looks like such an approach might work I can help flesh out the details. The key lies in the precision of the Data_list function. For details you can find the function in Global Functions:Analysis.
Mike Buess Origin WebRing Member |
 |
|
|
consoli
Germany
Posts |
Posted - 06/20/2007 : 05:34:18 AM
|
Thank you again for the help.
We are getting closer. What can be changed if the X-values look like this: 0.125, 0.236, 0.41, 0.499, 0.8, 0.934, 1.04, 1.187...
The Data_list command looks very useful here. If I reduce precision to zero and let's say im searching for time=1, will it give me the first entry with 1.xxx or value not found.
I will try it nevertheless.
This forum is really great and thanks again.
Angelo Consoli
|
 |
|
|
Mike Buess
USA
3037 Posts |
Posted - 06/20/2007 : 08:50:56 AM
|
If you set the precision to zero then Data_list will return the first row (0) in the dataset for every time value. Actually, LabTalk has the perfect function for your situation.quote: xindex(x, dataset) The xindex(x, dataset) function returns the index number of the first cell in the X dataset associated with dataset, where the cell value is less than or equal to x.
Requirements:
dataset must be a designated Y dataset.
The Y dataset name must correspond to an actual Y dataset.
The X dataset must be sorted in ascending order.
If your worksheets are standard A(X),B(Y) then test(1.0)= will return the index 6 for your time values...
int test(double dXval) { Worksheet wks = Project.ActiveLayer(); string sCmd = "i = xindex(" + dXval + "," + wks.Columns(1).GetDatasetName() + ")"; wks.LT_execute(sCmd); double dVal; LT_get_var("i", &dVal); return (int) dVal; }
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 06/20/2007 08:53:40 AM |
 |
|
|
consoli
Germany
Posts |
Posted - 06/21/2007 : 12:02:56 PM
|
Thanks a lot!
This is exactly what I was searching for.
I will post the script when it is finished.
Angelo Consoli
|
 |
|
| |
Topic  |
|
|
|