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
 delete alternate 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
vamsi2325 Posted - 10/13/2009 : 5:43:14 PM
Origin Ver. and Service Release (Select Help-->About Origin): Original Pro 8
Operating System: XP
I am trying to delete alternate rows using the script provided at
http://originlab.com/www/helponline/Origin8/en/Quickhelp/QuickHelp/How_do_I_delete_every_nth_row_or_column_from_my_worksheet.html
which is
// Delete every nth row, couting from the top
int ndel = 3; // change this number as needed;

int nrows = wks.nrows;
int nlast = nrows - mod(nrows, ndel);

// Start deleting from the bottom to the top
for(int ii = nlast; ii > 0; ii -= ndel)
{
range rr = wcol(1)[$(ii):$(ii)];
mark -d rr;
}
The above code is working for upto 50000 rows and I have 2 million rows. When I used the above code with 2 million rows it deletes all cloumns and shows 'commond error' in the script window.
Please help me in fixing this. I am new to origin.

Thanks
4   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 10/20/2009 : 09:45:19 AM
Excellent idea from rLewis!

We will expose the following Origin C method to Worksheet class to make this easier (without adding new col) in 8.1



	/**
			Reorder the worksheet with specified orders
		Parameters:
			vnOrder=[input] the orders of the rows to reorder
			nC1=[input]The first column
			nC2=[input]The last column, -1 means the last column in the worksheet
			bUndo=[input] undo or not
		Returns:
			true if success, otherwise false
	*/
	BOOL Reorder(const vector<uint>& vnOrder, int nC1 = 0, int nC2 = -1, BOOL bUndo = FALSE);



We will then use this method in the new wdelrows X-Function in 8.1.


CP
rlewis Posted - 10/19/2009 : 5:24:20 PM
After several rounds of testing, I found that when algorithms based on the the deletion of individual Worksheet rows are used, the execution time seems to increase nonlinearly as the number of Worksheet rows increases. I have therefore developed an alternative approach based on the Worksheet sort function. This approach executes more quickly and it seems that the execution time increases linearly with the number of worksheetwors. The code listed below is is an OriginC approach with which the following performance is typical on my workstation ...

Worksheet size = 200000 rows ... execution time ~1.35 sec
Worksheet size = 2000000 rows ... executiontime = 14.6 sec

By way of comparison approaches based on the deletion of individual worksheet rows gives the following results
Worksheet size = 25000 rows ... execution time ~13 sec
Worksheet size = 200000 rows ... execution time ~105 sec


bool DeleteAltRows(int StartNum)
{
	Worksheet Wks(Project.ActiveLayer());
	if(Wks.IsValid()==true && StartNum>=0 && StartNum<Wks.GetNumRows())
	{
		waitCursor Deleting;
		vector<uint> RowIndices;
		uint NumRows=Wks.GetNumRows();
		RowIndices.SetSize(NumRows);
		RowIndices.Data(0,NumRows-1,1);
		int NumToDelete=0;
		for(int i=StartNum+1;i<NumRows;i+=2)
		{
			RowIndices[i]+=NumRows;
			NumToDelete++;
		}
		string strTemp="rnInsert";
		string strTemp1;
		if(Wks.InsertCol(0,strTemp,strTemp1)==false) return false;
		Dataset dS0;
		if(dS0.Attach(Wks,0)==true)
		{
			dS0.SetSize(NumRows);
			dS0=RowIndices;
			Wks.Sort();
			if(Wks.SetNumRows(NumRows-NumToDelete)==true )
			{
				if(Wks.DeleteCol(0)==true)
				{
					return (true);
				}
			}
		}
	}
	return (false);
}

vamsi2325 Posted - 10/14/2009 : 4:58:32 PM
Easwar

many thanks for your help. it worked. But it took around 1 hour to complete the task for 2 million rows with 2GB ram. Is there any otherway to do this within shorter time.

Also, let me know what the #7 mean in the string 'range rr = wcol(1)[$(ii,#7):$(ii,#7)];'?
When is the next version is due for release?

Thanks again for your help.
Vamsi
easwar Posted - 10/14/2009 : 12:28:44 PM
Hi,

Thanks for reporting this, it is a bug in range definition that causes the failure, we will fix in next version.

In the mean time you can replace this line
range rr = wcol(1)[$(ii):$(ii)];
with this:
range rr = wcol(1)[$(ii,#7):$(ii,#7)];

and that should work.

In the next version we are also introducing tools to reduce data, so you will not have to run a loop in script.

Easwar
OriginLab

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