Author |
Topic  |
|
WilsonCM
USA
Posts |
Posted - 01/25/2005 : 1:44:18 PM
|
Origin Version (Select Help-->About Origin): 7.5 SR4 Operating System: Windows XP Pro
Greetings
We are attempting to organize a data set that has 3 variables(Time, X,Y). The data has about 10 time points and ~1000 X,Y pairs for each time point. How can we seperate the X,Y data from each time point out of the data set so that we can look at them individually, w/o cut and paste? The final goal is to integrate the X,Y data from each time point. |
|
easwar
USA
1965 Posts |
Posted - 01/25/2005 : 1:51:30 PM
|
Hello,
Is this large dataset already in a single worksheet, or is it on disk waiting to be imported/read?
Once data is in a worksheet, it is easy to extract part of the worksheet such as a range of cells, certain columns etc and then perform operations on them such as integration, or graphing etc.
It is also possible to write custom imports to get part of the data if it resides in a file etc.
Such tasks can be programmed using Origin C or LabTalk script. Perhaps you could post more details either here or in the programming forums and someone will post code segments to show you how to do this.
Easwar OriginLab
Edited by - easwar on 01/25/2005 1:57:21 PM |
 |
|
WilsonCM
USA
Posts |
Posted - 01/31/2005 : 11:20:18 AM
|
Thanks for the reply
Is this large dataset already in a single worksheet, or is it on disk waiting to be imported/read?
It is already in one worksheet. We have extracted the data to only show the data that we're interested in. Our data set is a 3D data set (time,x,y) and we want to seperate it into it's individual time slices. |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 01/31/2005 : 12:11:46 PM
|
Probably easiest to use Analysis->Extract Worksheet Data. To create a new worksheet containing only the rows for which the time value is 10 write your if-statement like this...
col(1)[i]==10
...After reading Easwar's response I should clarify that I have assumed an entirely different format for your worksheet. My solution is appropriate when your worksheet has only 3 columns...
time X Y 1 x y 1 x y 1 x y ... 10 x y 10 x y 10 x y ...
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 01/31/2005 12:45:26 PM |
 |
|
easwar
USA
1965 Posts |
Posted - 01/31/2005 : 12:21:09 PM
|
Hi WilsonCM,
I am assuming that your worksheet has about 10 rows (each corresponding to one time measurement) and over a 1000 columns, arranged such that the colums have T, X, Y, X, Y, X, Y, X, Y... data where the 1st column has the time info and the subsequent columns are the X, Y for the 1000 or so measurements for that time point.
If the above is not the case, please specify more details, or send the OPJ with data to tech support for help.
If the above is the way data is organized, you can use Origin C to get the X, Y data separated out for each time point, and then integrate the XY curve to obtain area etc. The following code segment shows how.
Easwar OriginLab
void integrate_txy() { // Declare worksheet object using active layer Worksheet wksData = Project.ActiveLayer(); if( !wksData ) { out_str("Active layer is not a worksheet!"); return; } // Create a new worksheet to hold results Worksheet wksResult(); wksResult.Create(); // Delete all existing columns and add two new cols while(wksResult.DeleteCol(0)); wksResult.AddCol("Time"); wksResult.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X); wksResult.AddCol("IntegValue"); // Set label and turn on label display WorksheetPage wpg = wksResult.GetPage(); wpg.Label = "Integration results from " + wksData.GetPage().GetName(); wpg.TitleShow = WIN_TITLE_SHOW_BOTH; // Get the raw TXYXYXY... data from the worksheet into a matrix object matrix matTemp; matTemp.CopyFrom(wksData); // Get number of rows and cols in matrix int nRows = matTemp.GetNumRows(); int nCols = matTemp.GetNumCols(); // Number of XY pairs will be (numcols-1)/2 int nNumXY = (nCols - 1) / 2;
// Create vectors to receive X and Y data vector vecX(nNumXY); vector vecY(nNumXY); // Loop over all rows (Time entries)... for( int iRow = 0; iRow < nRows; iRow++ ) { // Get time info and place in result worksheet wksResult.SetCell(iRow, 0, matTemp[iRow][0]); // Loop over all XY pairs and get XY data into vectors for( int iXY = 0; iXY < nNumXY; iXY++) { vecX[iXY] = matTemp[iRow][iXY * 2 + 1]; vecY[iXY] = matTemp[iRow][iXY * 2 + 2]; } // Generate a curve from the XY data Curve crvXY(vecX, vecY); // Perform integration and store integration area to result wks IntegrationResult irResult; BOOL bRet = Curve_integrate(&crvXY, &irResult); wksResult.SetCell(iRow, 1, irResult.Area); }
}
|
 |
|
WilsonCM
USA
Posts |
Posted - 01/31/2005 : 1:50:11 PM
|
Mike Buess: That is indeed how our data looks. Thank you
Easwar: I'm not all that familiar with C or the origin language. The only language I somewhat know is FORTRAN 77. So, I'm able to follow what you're doing there. How can I incorporate the format of our data to work with what you wrote?
Thanks for all of your help.
--Chris |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 01/31/2005 : 4:15:12 PM
|
Hi Chris,
The Origin C function below was modified from one created for a similar problem. Use it like this...
1. Open CodeBuilder (View->CodeBuilder). 2. Create a new C file (File->New). Select C File at top of file dialog, check Add to Workspace and Fill with default contents. Enter a name and location. Click OK. 3. Copy the code from this post and paste it at the end of your new file. 4. Select Tools->Rebuild All. You should see these messages...
compiling... filename.c Linking... Done!
5. Close CodeBuilder and open the script window (View->Script Window). 6. Make sure your worksheet is active (on top). 7. Type the following command in script window and press Enter where indicated...
split_wks<Press Enter>
That's it.
#Code starts here void split_wks() { Worksheet wks = Project.ActiveLayer(); matrix mm,mx; mm.CopyFromWks(wks); // easier to manipulate as matrix vector vv,vd; mm.GetColumn(vv,0); // get time column as vector vv.Difference(vd); // create difference (between adjacent elements) vector vd.Add(1.0); // add nonzero element at the end int i,i1,i2; for(i=0; i<mm.GetNumRows(); i++) { if( vd[i]!=0 ) { i1 = i2; i2 = i+1; mm.GetSubMatrix(mx,0,-1,i1,i2-1); new_wks(mx); } } } void new_wks(matrix mx) { Worksheet wks; wks.Create(); Dataset dd; for(int i=0; i<mx.GetNumCols(); i++) { if( i>1 ) wks.AddCol(); dd.Attach(wks,i); mx.GetColumn(dd,i); } }
Mike Buess Origin WebRing Member |
 |
|
|
Topic  |
|
|
|