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 data below certain length
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

AliceInNanoland

Germany
2 Posts

Posted - 09/05/2017 :  09:45:00 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 2016 (64bit) Sr2
Operating System: Windows 8.1

I have data of trajectories and would like to delete those trajectories that are shorter than a certain threshold.
My raw data contains 3 columns: x and y coordinates and another column that specifies the trajectory number, e.g.

Table 1
traject x y
1 155.006 106.805
1 155.117 107.313
2 84.284 164.696
2 84.482 163.961
2 84.306 164.881
2 84.979 164.756
2 84.958 165.243
3 162.371 219.024
3 161.802 218.693
3 161.633 218.296
4 211.152 227.07
4 211.43 228.763
4 211.291 228.906
4 212.383 228.686
4 211.597 227.746
4 210.911 229.137

I can unstack the columns according to the trajectory number like this:

Table 2
x y x y x y x y
1 1 2 2 3 3 4 4
155.006 106.805 84.284 164.696 163.132 218.51 211.152 227.07
155.117 107.313 84.482 163.961 163.45 219.063 211.43 228.763
84.306 164.881 162.464 218.66 211.291 228.906
84.979 164.756 212.383 228.686
84.958 165.243 211.597 227.746
210.911 229.137

But I don't need the shorter trajectories, e.g. trajectories 1 and 3 that have only 3 or fewer rows.
Is there a possibility to either delete the rows of these trajectories in Table 1 or to delete the columns of these trajectories in Table 2?

I'm not very experienced with Origin yet and I've been picking the longer trajectories out of thousands of trajectories by hand which is very very tedious...therefore, I would be happy if anyone could help me!

PhD Student
Institute of Chemistry and Biochemistry
Freie Universität Berlin

Hideo Fujii

USA
1582 Posts

Posted - 09/05/2017 :  11:07:32 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi AliceInNanoland,

Maybe the following code can do such job. Please try.
colthresh=3;  //threshold
nc=wks.nCols;
for(ii=nc; ii>=1; ii--) {
  range rr=wcol(ii); 
  if(rr.getSize()<=colthresh) del wcol(ii); //delete if shorter than threshold
}
Hope this helps.

--Hideo Fujii
OriginLab
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 09/05/2017 :  2:21:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi AliceInNanoland and visitors to this thread,

This is an addendum to my previous post. Although probably it doesn't matter in this specific situation for
the unstacked result, if the column contains missing values at the end of the dataset, rr.getSize() would return
the inflated value. To avoid such case, and to get the "actual" dataset size, you may want to define a function
like:
function double getActualSize(range ra) {
  int icnt, irow=ra.getSize();
  for(icnt=irow; icnt>=1; icnt--) if(ra[icnt]$!="" && ra[icnt]$!="--") break;
  return icnt;
}
Then, the code could be written like:
colthresh=3;  //threshold
nc=wks.nCols;
for(ii=nc; ii>=1; ii--) {
  range rr=wcol(ii); 
  if(getActualSize(rr)<=colthresh) del wcol(ii); //delete if shorter than threshold
}
Hope this suggestion helps in some situations.

--Hideo Fujii
OriginLab
Go to Top of Page

AliceInNanoland

Germany
2 Posts

Posted - 09/14/2017 :  11:54:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Dear Hideo Fujii, thanks for the quick reply. It works, thank you!

PhD Student
Institute of Chemistry and Biochemistry
Freie Universität Berlin
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