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 for Programming
 Forum for Origin C
 Arrays of Datasets or vectors
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Ph_Leick

Germany
2 Posts

Posted - 10/15/2003 :  08:12:46 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Is it possible to create Arrays of Datasets or Vectors in OriginC?
If yes, how can the elements of these be accessed?

Philippe

Mike Buess

USA
3037 Posts

Posted - 10/15/2003 :  08:38:24 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Philippe,

Only 2D arrays (matrices) are supported in OriginC. Use the Matrix and matrixbase classes to access columns, rows or cells.

Mike Buess
Origin WebRing Member
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 10/15/2003 :  1:44:12 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Currently, only vector and matrix can be used in an array, but Dataset and Matrix does not. Maybe you can use the CopyFromWks function in matrix class to construct a matrix from a range of worksheet cells and then process the data in that matrix.

The following function can be used to demonstrate this. change your custom.ogs as

[Main]
show_sel_stat;



void show_sel_stat()
{
Worksheet wks = Project.ActiveLayer();
if(!wks)
return;

int r1, c1,r2, c2;
int seltype = wks.GetSelectedRange(r1, c1, r2, c2);
if(WKS_SEL_NONE == seltype)
return;

matrix mm;

if(mm.CopyFromWks(wks, c1, c2, r1, r2))
{
printf("Selection %d x %d: mean = %f\n", mm.GetNumRows(), mm.GetNumCols(), mm.GetMean());
}
}





Once you compile this, can then select any data in a worksheet and hit the Custom Routine button.

CP



Edited by - cpyang on 10/15/2003 2:33:11 PM
Go to Top of Page

Gary Lane

USA
150 Posts

Posted - 10/22/2003 :  3:14:11 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The following function will work in v7.5727. Customers will see this in Origin 7.5 SR1.

Gary

*********************************************************************

BOOL AccessingArrayOfDatasets()
{
Worksheet wks = Project.ActiveLayer(); // Get active worksheet layer
if( wks.IsValid() ) // If wks is valid..
{
uint nCols = wks.Columns.Count(); // Get number of columns in worksheet
nCols = nCols > 10 ? 10 : nCols; // Maximum number of columns is 10
Dataset ards[10]; // Declare an array of datasets
for( int ii = 0; ii < nCols; ii++ ) // For each column in worksheet...
{
ards[ii].Attach(wks, ii); // Attach to Dataset in ii-th column
if( !ards[ii].IsValid() ) // Continue if attach fails
continue;
string strName = ards[ii].GetName(); // Get name of ii-th Dataset
int iSize = ards[ii].GetSize(); // Get size of ii-th Dataset
if( iSize > 0 )
{
double dFirstVal = ards[ii][0]; // Get first value of ii-th Dataset
printf("Dataset %s has %d elements the first of which is %g\n", strName, iSize, dFirstVal);
}
else
printf("Dataset %s has %d elements\n", strName, iSize);
}
return TRUE;
}

return FALSE;
}



Edited by - Gary Lane on 10/22/2003 4:31:23 PM
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