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 some specific 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

umcp999

USA
Posts

Posted - 03/16/2005 :  10:12:38 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin):
Operating System:winxp
Hi

I have one question about deleting some specific rows in a worksheet. I wonder how to do that with labtalk. Here is one of my examples. I have this worksheet. I want to delete all rows which the first column's absolute value is less than 0.2 (for example). For the following worksheet, I have to delete 3 rows:

0.01 4.9E-6 2040.81633
0 1.1E-6 0
0 1.7E-6 0

Thanks



worksheet
=====================================

0.01 4.9E-6 2040.81633 <-----
-0.49 -2.932E-4 1671.21419
-0.99 -6.674E-4 1483.36829
-1.49 -0.00105 1415.13914
-1.99 -0.00145 1375.44927
-2.49 -0.00178 1397.46324
-2.99 -0.00209 1427.82102
-3 -0.00201 1491.27604
-2.5 -0.00163 1531.01843
-2 -0.00127 1577.78479
-1.5 -9.175E-4 1634.87738
-1 -5.81E-4 1721.1704
-0.5 -2.696E-4 1854.59941
0 1.1E-6 0 <-----
0.5 2.718E-4 1839.58793
1 5.881E-4 1700.39109
1.5 9.585E-4 1564.94523
2 0.00155 1286.91847
2.5 0.00217 1152.76433
3 0.00273 1100.67508
3 0.00306 979.8798
2.5 0.00251 996.96921
2 0.00197 1016.72513
1.5 0.00144 1041.01603
1 9.34E-4 1070.66381
0.5 4.512E-4 1108.15603
0 1.7E-6 0 <-----
-0.5 -4.539E-4 1101.56422
-1 -9.317E-4 1073.30686
-1.5 -0.00144 1040.79933
-2 -0.00197 1013.1199
-2.5 -0.00252 992.8909
-3 -0.00306 978.95252
-3.5 -0.00364 962.8081
-4 -0.00418 955.90871
-4.5 -0.0038 1184.42871
-5 -0.00391 1277.59608

Mike Buess

USA
3037 Posts

Posted - 03/16/2005 :  10:19:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Easiest way to do that is with Analysis > Extract Worksheet Data. Use abs(col(1)[i])>0.2 as the condition.

Mike Buess
Origin WebRing Member
Go to Top of Page

umcp999

USA
Posts

Posted - 03/16/2005 :  10:40:40 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for your help. Is there any other ways that could be programmed in labtalk? My task is to open lots of data files with specific format, delete those extaneous Rows, and plot them in doubly y format. I have programmed to open lots of data files and plot them in doubly y format. But these days I have to delete those extraneous rows by myself. I do not want to extract data to create a new worksheet. I want to delete them just within the original worksheet. Is it possible?
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 03/16/2005 :  10:56:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
get %(%H,1) -e npt; // number of rows
wo -a 1; // add a column at the end
%(%H,wks.ncols)=data(1,npt); // fill it with row numbers
%(%H,1)=abs(%(%H,1))<0.2?0/0:%(%H,1); // replace values in col 1 with abs(val)<0.2 with missing values
sort -w %H %(%H,1); // sort wks according to col 1 (this puts missing values at the end)
sum(%(%H,1)); // sum col 1 (sum.n is number of actual values)
set %H -er sum.n; // resize wks to number of actual values
sort -w %H %(%H,wks.ncols); // sort wks according to original row numbers (restore original order)
del %(%H,wks.ncols); // delete sorting column

If you have Origin 6.1 SR2 or higher you can replace the ternary operator in line 4 with the faster tReplace function.

Mike Buess
Origin WebRing Member
Go to Top of Page

umcp999

USA
Posts

Posted - 03/16/2005 :  11:00:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for your help. Also I found your previous post at this forum. This might help me also. Thanks

win -d; // duplicate active wks
doc -e W {%W=%H}; // Find the name of the last wks created (your duplicate)
win -r %W DataTemp; // rename it DataTemp
win -a DataTemp; // activate DataTemp
// The rest is the LabTalk equivalent to a while loop
for(i=1;i>0;) {
if(col(RTMeasurement)[i]==0/0) break; // abort when you find missing value (no data)
if(abs(col(RTMeasurement)[i])>0.2) i++; // increment row index if condition is met
else {
mark -d col(B) -b i -e i; // delete row i if condition not met
};
};
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