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
 Deleting rows and rearrange the remaining 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
stingray21 Posted - 09/21/2011 : 05:10:08 AM
Hallo,

I’m new in the forum and not a native English speaker. So I’m 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 I’d 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 can’t 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.

We’re working with Origin 8G SR2 (v.8.0891).

Thank You
11   L A T E S T    R E P L I E S    (Newest First)
stingray21 Posted - 09/23/2011 : 1:58:06 PM
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;

Sam Fang Posted - 09/22/2011 : 10:10:29 PM
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
LabTalk user Posted - 09/22/2011 : 5:33:36 PM
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!
stingray21 Posted - 09/22/2011 : 2:22:09 PM
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.
DataConv Posted - 09/22/2011 : 09:11:53 AM
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...
stingray21 Posted - 09/22/2011 : 07:37:38 AM
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.
DataConv Posted - 09/22/2011 : 06:51:25 AM
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...
stingray21 Posted - 09/22/2011 : 05:06:22 AM
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?
Sam Fang Posted - 09/21/2011 : 10:21:17 PM
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
stingray21 Posted - 09/21/2011 : 2:42:48 PM
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
Sam Fang Posted - 09/21/2011 : 06:32:15 AM
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

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