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
 LabTalk Forum
 Maximum values in a new sheet

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
Clairekun Posted - 02/18/2013 : 03:41:26 AM
Origin Ver. and Service Release (Select Help-->About Origin): 9
Operating System: Windows 7

Hello,

I have a worksheet with one X column and many Y columns. I would need to find the maximum value for every Y column and paste all those X-Y coordinates in a new sheet or book. How could I do this?

There are similar posts here, but I couldn't find a solution that fitted my needs. Sorry if I missed it.
4   L A T E S T    R E P L I E S    (Newest First)
cdrozdowski111 Posted - 03/01/2013 : 08:05:29 AM
The code below is a bit of an improvement. It allows you to either go through every worksheet in the whole project or only those in a selected folder in Project Explorer (except that it will NOT go into subfolders if this method is chosen).

If you look in the code there will be two "doc" commands, one of which is commented out. You can change which one is commented out to change the behavior according to your wishes.


string strName$; // String to hold name of new book
newbook result:= strName$; // Create new workbook putting it's name into strName$

range rngNewCol1 = [%(strName$)]Sheet1!col(1); // Get column 1 of newly created workbook, sheet 1
range rngNewCol2 = [%(strName$)]Sheet1!col(2); // Get column 2 of newly created workbook, sheet 1

int jj = 1; // Counter for adding rows to columns in new workbook


// !!! The following command loops over every worksheet in the whole project
doc -e LB {

// !!! The following command loops over every worksheet in a selected folder in Project Explorer. Does NOT look in subfolders
//doc -ef LB {


	if (exist(%H, 2) == 0) // Not a workbook, must be a matrix
	{
		continue;
	}

	if (%H == strName$) // Skip newly created workbook
	{
		continue;
	}

	range rngX = col(1); // The current worksheet X column

	// Loop over all Y columns in current worksheet
	for(int ii = 2 ; ii <= wks.ncols; ii++)
	{
		range rngY = col($(ii)); // The current worksheet Y column

		limit rngY; // Puts some stats into tree LIMIT

		rngNewCol1[jj] = rngX[limit.imax]; // Get X of row with maximum. Put into column 1 of newly created workbook
		rngNewCol2[jj] = rngY[limit.imax]; // Get Y of row with maximum. Put into column 2 of newly created workbook
		
		jj++; // Increment jj counter for adding rows to columns
	}
}
cdrozdowski111 Posted - 02/27/2013 : 7:33:44 PM
The following will go through every worksheet of every workbook in the current project (it might not be the most efficient code but seems to work okay based on a quick test):


dataset dsXCol = {}; // Dataset to hold X column data for new workbook- assigned at end of script
dataset dsYCol = {}; // Dataset to hold Y column data for new workbook

string strName$; // String to hold name of new book
newbook result:= strName$; // Create new workbook putting it's name into strName$

int jj = 1; // Counter for adding rows to above datasets


// Loop over every worksheet in project
doc -e LB {

	if (exist(%H, 2) == 0) // Not a workbook, must be a matrix
	{
		continue;
	}

	if (%H == strName$) // Skip newly created workbook
	{
		continue;
	}

	range rngX = col(1); // The current worksheet X column

	// Loop over all Y columns
	for(int ii = 2 ; ii <= wks.ncols; ii++)
	{
		range rngY = col($(ii)); // The current worksheet Y column

		limit rngY; // Puts some stats into tree LIMIT

		dsXCol[jj] = rngX[limit.imax]; // Get X of row with maximum. Put into dsXCol dataset using jj counter
		dsYCol[jj] = rngY[limit.imax]; // Get Y of row with maximum. Put into dsYCol dataset
		
		jj++; // Increment jj counter for adding rows to above datasets
	}
}


range rngCol1 = [%(strName$)]Sheet1!col(1); // Get column 1 of newly created workbook, sheet 1
range rngCol2 = [%(strName$)]Sheet1!col(2); // Get column 2 of newly created workbook, sheet 1

rngCol1 = dsXCol; // Assign X dataset to column 1
rngCol2 = dsYCol; // Assign Y dataset to column 2

Clairekun Posted - 02/26/2013 : 04:42:17 AM
Thank you, it works like a charm!

If I needed to loop through several worksheets, though, how could I do it? I haven't found this option under "Range Notation" in the wiki, and setting no range at all (so that it would be applied to all workbooks) results in the creation of endless new workbooks until Origin crashes.
greg Posted - 02/18/2013 : 4:32:50 PM
This should do it:

range raw = [Book1]Sheet1; // Your book and sheet
ncols = raw.ncols; // total number of your columns (assume x is first)
newbook;
range rax = 1; // column for x output
range ray = 2; // column for y output
range radx = raw!1; // The original x column
// loop over all y columns
for( ii = 2 ; ii <= ncols ; ii++ )
{
range rad = raw!$(ii); // next y column
limit rad; // Puts some stats into tree LIMIT.
rax[ii-1] = radx[limit.imax]; // Get x of row with maximum
ray[ii-1] = rad[limit.imax]; // Get y of row with maximum
}

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