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
 Deleting rows and rearrange the remaining 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

stingray21

8 Posts

Posted - 09/21/2011 :  05:10:08 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hallo,

Im new in the forum and not a native English speaker. So Im sorry for my poor English.

I have a work sheet with two columns (voltage and current). The column with voltage has values like

voltage
1.00
0.99
0.98

0.02
0.01
0
-0.01
-0.02

-0.99
-1.00

And the other column holds the corresponding current values. Now Id like to delete all rows with negative voltage values. I already wrote this piece of code, which is working and from which I get the first and last row that I want to delete.

range bb = 2;									
int numberOfRows = bb.GetSize();
del -v bb;									
int jjstart = 1;							
int jjend = 1;									
loop (jj, 1, numberOfRows)						
{
if (Cell(jj,2) < 0)
	{
		jjend = jj;
	}
}	
del -v jj;										
type "Rows to delete: $(jjstart) to $(jjend)";


But I cant figure it out, how to delete these rows. I googled my problem, but found no solution that worked.

My second problem is, that I need to rearrange the remaining rows, so that I have ascending voltage values.

I would be very grateful for any help.

Were working with Origin 8G SR2 (v.8.0891).

Thank You

Sam Fang

293 Posts

Posted - 09/21/2011 :  06:32:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can first sort the sheet by the voltage in descending order. And find the row number for the first negative voltage. Then use wks.nrows to set the number of rows for the sheet. Finally sort the sheet by the voltage in ascending order. Script can be as follows.
--------------------------------------------------
col(C)=col(A)>=0?1:-1;
sort -wd [Book1]Sheet1 col(A);
rn=list(-1,col(C));
wks.nrows=rn-1;
del -s col(C);
sort -w [Book1]Sheet1 col(A);

--------------------------------------------------

Sam
OriginLab Technical Services

Edited by - Sam Fang on 09/21/2011 10:18:40 PM
Go to Top of Page

stingray21

8 Posts

Posted - 09/21/2011 :  2:42:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank You for the answer, I think the approach could work.
The problem is, that is part works fine


col(C)=col(A)>0?1:-1;
sort -wd [Book1]Sheet1 col(A);
rn=list(-1,col(C));


but after I use this command


wks.nrows=rn-1;


the sheet has indeed rn-1 rows, but the sheet is also empty!


Best Regards
Go to Top of Page

Sam Fang

293 Posts

Posted - 09/21/2011 :  10:21:17 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It's a bug of 8.0SR2. You can update your Origin to 8.0SR6.

Select Help: Check for Updates from Origin menu.

Sam
OriginLab Technical Services

Edited by - Sam Fang on 09/21/2011 10:21:50 PM
Go to Top of Page

stingray21

8 Posts

Posted - 09/22/2011 :  05:06:22 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I can try to ask the admin to update origin, but I doubt he has time to do it for me.

Is there no other possibility to delete rows in a work sheet?

Edited by - stingray21 on 09/22/2011 05:07:34 AM
Go to Top of Page

DataConv

Germany
60 Posts

Posted - 09/22/2011 :  06:51:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Maybe this code works for you:
range r1=!1;
loop(ii,1,r1.nrows){r1<ii>=(r1[ii]<0);};
mark -md r1;

This code is written to search in the first column row for row for negative values, if so marking them and finally delete all marked rows...
Go to Top of Page

stingray21

8 Posts

Posted - 09/22/2011 :  07:37:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the answer.

Unfortunately


range r1=!1;
loop(ii,1,r1.nrows){r1<ii>=(r1[ii]<0);};
mark -md r1;


doesn't work either.

I get "--" in all cells of the first column und the cells with previous negative values are colored red.
Go to Top of Page

DataConv

Germany
60 Posts

Posted - 09/22/2011 :  09:11:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can try this then:
range r1=!1;
dataset d01;
d01=sign(r1);
r1/=sign(d01+1);
wdelrows m:=1 r:=r1;

First, the rows with negative numbers in the first column are converted to missing values (by dividing by 0), then the rows with the missing values are deleted using the wdelrows XFunction...
Using the conditional operator ?: for setting the missing values should work also, but execution takes longer...
Go to Top of Page

stingray21

8 Posts

Posted - 09/22/2011 :  2:22:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you all for the suggestions, unfortunately none of theme got me the result I need.

I can't believe there is no simple way to delete rows. In the user interface I can mark one or more rows and choose in the context menu (by right clickin on the marked rows) "delete rows". Why isn't something like this possible by a script?

Is there another possibilty (maybe to ignore the rows), so they are not relevant for later calculations (for example linear fit or derivatives) and the plots.
Go to Top of Page

LabTalk user

USA
35 Posts

Posted - 09/22/2011 :  5:33:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

I run into some weird issues when using Labtalk as well. The command (menu -e 36442;) is identical to delete. If you highlight all the rows and then run this command it will do what you're looking for. It doesn't leave the "--", it deletes the row. You don't need the parentheses by the way.

Look on the wiki about the menu -e command for a better description of how it works. I've found that even though some of the easy commands don't work, there is a way to do what you want.

Hopefully this works for you!
Go to Top of Page

Sam Fang

293 Posts

Posted - 09/22/2011 :  10:10:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can also extract rows in a new sheet for positive voltages. It can work in 8.0SR2.
---------------------------------------------------------
wxt test:="col(A)>=0" ow:=<new>;
wsort bycol:=1;

---------------------------------------------------------

Sam
OriginLab Technical Services
Go to Top of Page

stingray21

8 Posts

Posted - 09/23/2011 :  1:58:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you all for your help.

I have a solution for my problem, so special thanks to "LabTalk user".


wxt "col(2)<=0" sel:=1;
menu -e 36442;

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