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
 LabTalk Forum
 delete alternate rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

vamsi2325

USA
2 Posts

Posted - 10/13/2009 :  5:43:14 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

easwar

USA
1964 Posts

Posted - 10/14/2009 :  12:28:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

vamsi2325

USA
2 Posts

Posted - 10/14/2009 :  4:58:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 10/19/2009 :  5:24:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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);
}

Go to Top of Page

cpyang

USA
1406 Posts

Posted - 10/20/2009 :  09:45:19 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
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