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
 Forum for Origin C
 Arrays of Datasets or vectors

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
Ph_Leick Posted - 10/15/2003 : 08:12:46 AM
Is it possible to create Arrays of Datasets or Vectors in OriginC?
If yes, how can the elements of these be accessed?

Philippe
3   L A T E S T    R E P L I E S    (Newest First)
Gary Lane Posted - 10/22/2003 : 3:14:11 PM
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
cpyang Posted - 10/15/2003 : 1:44:12 PM
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
Mike Buess Posted - 10/15/2003 : 08:38:24 AM
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

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