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
 Origin Forum
 Deleting rows with no continous range
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

bmmaoso

Colombia
Posts

Posted - 09/13/2004 :  10:30:00 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello, My origin version is 6.0.
I want to delete some rows from a worksheet, but I am not sure how to do it. In my labtalk I need to delete the rows with null value. My labtalk is:
n=wks.nrows;
for (i=1;i<=n;i++){
if (col(Mass)[i] == --){
work -s 1 i 13 i;
mark -w1;
mark -d %B_Mass 1 i 13 i}; //delete rows (but it doesn't work)
};

Thank you for your help.
Maria Isabel

Mike Buess

USA
3037 Posts

Posted - 09/13/2004 :  11:36:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Maria,

If wks Data1 has a column named B then this command...

mark -d Data1_B -b r1 -e r2;

will delete rows r1 through r2 from the entire worksheet. Set r2=r1=i to delete just row i and your script will look like this...

n=wks.nrows;
for(i=1;i<=n;i++) {
if(col(Mass)[i] == 0/0) {
mark -d %B_Mass -b i -e i; // delete row i
};
};

(0/0 gives a null value which shows up as -- in the wks.)

...There's a much faster way to do this if your wks %B has a sorted column. For example, if col A contains increasing X values you can do the following.

sum(%B_Mass);
nn=sum.n; // this is the number of numeric (non-missing) values in the Mass col
sort -w %B %B_Mass; // sort wks in ascending order of col Mass. (This will send all null values to the bottom.)
set %B -er nn; // set # of rows in %B equal to nn. (Remove all null values.)
sort -w %B %B_A; // sort wks in ascending order of col A. (Return to original order.)

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 09/13/2004 12:03:26 PM
Go to Top of Page

bmmaoso

Colombia
Posts

Posted - 09/14/2004 :  04:23:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much

The first option to not work, I don't know why, but it delete most of the columns. However, the second one works really good.

To work successfully with the second option I have other problem, my first column in the wks is a time and date column (hh:mm:ss dd/mm/yy), but I need to leave only the time in this column with hh:mm:ss format. If I leave only the hh:mm format, the second option you gave me doesn't work successfully. I have a labtalk, but it set the seconds 00. Also, I change the custum Date format to hh:mm:ss as a second option but I have problems:

wks.col1.format=3; //time format
wks.col1.subformat=2; //time format (but it set seconds as 00)
or
wks.col1.format=4; //date format
wks.col1.subformat=20 //subformat custum1 (hh:mm:ss)(but it show the column as null values)

If I do the second option manually it works. So I think there should be an option to do it with labtalk.

Thank you very much for your help
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 09/14/2004 :  07:45:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Easier to create a new sorting column...

sum(%B_Mass); nn=sum.n; // how many values in Mass col?
get %B_Mass -e nrow; // how many rows?
win -o %B {
wo -c; // add col at end
%S=wks.col$(wks.ncols).name$; // save its name
};
%B_%S=data(1,nrow); // fill col with row numbers
sort -w %B %B_Mass;
set %B -er nn;
sort -w %B %B_%S;
del %B_%S; // delete sorting column

Mike Buess
Origin WebRing Member
Go to Top of Page

bmmaoso

Colombia
Posts

Posted - 09/14/2004 :  08:54:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you Mike, my wks works successfully.
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 09/14/2004 :  10:54:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The first method fails because the number of filled rows changes when you delete a row. This modification works fine...

get %B_Mass -e nn; // number of filled rows (can be less than wks.nrows)
mm=nn;
for(i=1;i<=nn;i++) {
if(i>mm) break;
if(%B_Mass[i]==0/0) {
mark -d %B_Mass -b i -e i;
mm--;
};

...Even that script has problems with consecutive nulls. The following seems to work better.

get %B_Mass -e mm;
for(i=1;i>0;) {
if(i>mm) break;
if(%B_Mass[i]==0/0) {
mark -d %B_Mass -b i -e i;
mm--;
};
else i++;
};

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 09/14/2004 1:40:37 PM
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