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 columns and statistics on rows

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
oconnor Posted - 11/23/2004 : 08:52:28 AM
Origin Version (Select Help-->About Origin): 7.5
Operating System: Win XP

Hi,

How do I go about setting up a Dataset that is an array of columns and then performing the equivalent to "Statistics on Rows" on this dataset?

Cheers,

Rod

Edited by - oconnor on 11/23/2004 09:44:02 AM
6   L A T E S T    R E P L I E S    (Newest First)
easwar Posted - 11/23/2004 : 1:45:11 PM
Hi Rod,

Just an OC note.

If you use the code I posted first that copies from wks into a matrix, then please replace the CopyFromWks method to just CopyFrom. The later is a new method that was added recently and has more flexibility.

So the utility function will change as below, and will work the same



////////////////////////////////////////////////////////////////////////////
// This function copies a specific row of a worksheet to a vector
// Parameters:
// wks: Input, worksheet object passed by reference
// nRow: Input, row number to copy, counting from 0
// vecTemp: Output, on return will contain the values
// Return:
// 0: success
// 1: failed to get wks row data into temp matrix
// 1: failed to get temp matrix data into vector
//
int get_wks_row_as_vector( Worksheet& wks, int nRow, vector& vecTemp )
{
// First copy the specified row to a matrix object
matrix mat;
bool bRet = mat.CopyFrom( wks, 0, -1, nRow, nRow );
if( !bRet ) return 1;

// Now get the matrix data into a vector
bRet = mat.GetAsVector( vecTemp );
if( !bRet ) return 2;

return 0;
}
////////////////////////////////////////////////////////////////////////////




Easwar
OriginLab


easwar Posted - 11/23/2004 : 12:51:50 PM
Hi Rod,

Just to show how to loop over cells and check col type and add to vector, here is code that does that:

Easwar
OriginLab


int get_wks_row_as_vector_from_y_cols( Worksheet& wks, int nRow, vector& vecTemp )
{
vecTemp.SetSize( 0 );

int iNumCols = wks.GetNumCols();
if( iNumCols < 1 ) return 1;

for(int nCol = 0; nCol < iNumCols; nCol++ )
{
if( OKDATAOBJ_DESIGNATION_Y == wks.Columns( nCol ).GetType() )
vecTemp.Add( wks.Cell( nRow, nCol ) );
}
return 0;
}



Mike Buess Posted - 11/23/2004 : 12:49:15 PM
You could also duplicate the active wks, delete columns in the copy based on type and run Easwar's script on the result. To my mind adjusting the first column parameter in mat.CopyFromWks() is more elegant than either my or Easwar's alternative.

Mike Buess
Origin WebRing Member
easwar Posted - 11/23/2004 : 11:54:55 AM
quote:

But is there a more elegant way to specify only those columns whose plot designation is Y?



Hi Rod,

To acheive that you will need to build the vector by looping over each column of the row, checking the column plot designation and copying over the cell value only if the designation is Y.

Easwar
OriginLab

oconnor Posted - 11/23/2004 : 11:46:26 AM
Easwar,

Thanks. That works nicely. Is there any easy way to restrict the vector to only those columns where the plot designation is Y and not include the first column X (which is my time variable). I suppose I could set the first column parameter of the CopyFromWks as 1:

bool bRet = mat.CopyFromWks( wks, 1, -1, nRow, nRow );
if( !bRet ) return 1;

But is there a more elegant way to specify only those columns whose plot designation is Y?

Thanks again for your help,

Rod.
easwar Posted - 11/23/2004 : 10:37:01 AM
Hi Rod,

Currently there is no direct method to get a row of a wks into a dataset. In the code below, I have provided a function to copy a row of a wks into a vector (which internally first gets the wks data into a matrix and then copies to the vector). You can add that function to your workspace/system branch of CB if you want to use it repeatedly. Then, by calling that function you can get the row data into a vector first, and then perform stats on the vector - by copying it to a dataset and using BasicStat object, or by passing the vector to a NAG function.

Easwar
OriginLab



void test( int nRow)
{
// Declare wks object and check validity
Worksheet wks = Project.ActiveLayer();
if( !wks ) return;

// Get the specific row of the wks into a vector
vector vecTemp;
int iRet = get_wks_row_as_vector( wks, nRow - 1, vecTemp );
if( 0 != iRet )
{
out_str( "Failed to get row of wks into vector" );
return;
}

// Now copy the vector into a temp dataset and perform stats
// (or call NAG library function to directly comptue stats from vector)
Dataset dsTemp( vecTemp );
BasicStats bsStat;
Data_sum( &dsTemp, &bsStat );
printf("Mean = %f\n", bsStat.mean );
}


////////////////////////////////////////////////////////////////////////////
// This function copies a specific row of a worksheet to a vector
// Parameters:
// wks: Input, worksheet object passed by reference
// nRow: Input, row number to copy, counting from 0
// vecTemp: Output, on return will contain the values
// Return:
// 0: success
// 1: failed to get wks row data into temp matrix
// 1: failed to get temp matrix data into vector
//
int get_wks_row_as_vector( Worksheet& wks, int nRow, vector& vecTemp )
{
// First copy the specified row to a matrix object
matrix mat;
bool bRet = mat.CopyFromWks( wks, 0, -1, nRow, nRow );
if( !bRet ) return 1;

// Now get the matrix data into a vector
bRet = mat.GetAsVector( vecTemp );
if( !bRet ) return 2;

return 0;
}
////////////////////////////////////////////////////////////////////////////





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