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
 questions involving worksheet manipulation
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

davidseo

S. Korea
Posts

Posted - 12/29/2004 :  03:26:55 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version 7.5
Operating System:Windows XP

Hi, i am a newbie user with origin and I had a couple questions I could not find the answers to.

I have a worksheet containing 100 columns of data and 200 rows.
There are multiple NaN or -- spaces more or less randomly about
my worksheet.

I would like to ask three seperate questions:
1. Is it possible for me to sort each column by its respective values? (i.e. Not sort by the leftmost column)
For example, if i had 2 columns like:
1 5 0 3 0 6
3 3 i want it to be sorted as 1 4 not as 1 5
2 4 2 5 2 4
0 6 3 6 3 3
I know i can do this by manually selecting all columns but that is too much of a hassle (100 columns per wksheet, many sheets!)

2. Is it possible to remove ALL NaN and -- entries from my worksheet
and shift the values of each respective column upwards where appropriate?

3. Finally, How can I delete every nth column of data? (and have the rest of the columns be shifted to the left)

Please remember I am a newbie and have no experience with either Origin C or Labtalk, so if a solution involves these please be specific. Thanks in advance

-David Seo


Edited by - davidseo on 12/29/2004 03:31:12 AM

Mike Buess

USA
3037 Posts

Posted - 12/29/2004 :  12:50:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi David,

Here are some OriginC solutions...

1. This will sort each column in ascending order w.r.t to itself. (To sort in descending order use SORT_DESCENDING instead of SORT_ASCENDING.) The pg.SetShow() commands merely refresh the worksheet to show the changes.
void SortColumn()
{
Worksheet wks = Project.ActiveLayer();
Dataset dd;
foreach (Column cc in wks.Columns)
{
dd.Attach(cc);
dd.Sort(SORT_ASCENDING);
}
Page pg = Project.Pages();
pg.SetShow(PAGE_HIDDEN);
pg.SetShow(PAGE_ACTIVATE);
}
2. This will remove all NaN cells and shift remaining cells upwards.
void RemoveNaN()
{
Worksheet wks = Project.ActiveLayer();
Dataset dd;
foreach (Column cc in wks.Columns)
{
dd.Attach(cc);
dd.Trim();
}
}
3. Delete every Nth column...
void RemoveNthCol(int N)
{
Worksheet wks = Project.ActiveLayer();
int nCols = LabTalk.wks.ncols;
for(int i=nCols-1; i>=0; i--)
{
if( mod(i+1,N)==0 )
wks.DeleteCol(i);
}
}
Since you're new to OriginC and asked for details...

1. Open CodeBuilder from Origin's View menu.

2. Select New on CodeBuilder's File menu. In the resulting dialog,
2a. Enter a file name such as Test.c.
2b. Check both the Add to Workspace and the Fill with Default Contents options.
2c. Click OK.

3. Copy the three functions from this post and paste them into the new file.

4. Select Build on CodeBuilders Tools menu. You should see the following messages

compiling...
Test.c
Linking...
Done!

5. Return to Origin, make sure your worksheet is active and open the script window (View->Script Window). To execute one of your functions just type its name with arguments (if any) and hit Enter...

SortColumn<Enter>
RemoveNaN<Enter>

The third function needs the column increment as an argument, i.e., to remove every 4th column...

RemoveNthCol 4<Enter>

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 12/29/2004 2:15:30 PM
Go to Top of Page

davidseo

S. Korea
Posts

Posted - 12/29/2004 :  6:45:53 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Mike!
The code and information you provided me worked perfectly.
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