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
 Origin Forum
 questions involving worksheet manipulation

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
davidseo Posted - 12/29/2004 : 03:26:55 AM
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
2   L A T E S T    R E P L I E S    (Newest First)
davidseo Posted - 12/29/2004 : 6:45:53 PM
Thanks Mike!
The code and information you provided me worked perfectly.
Mike Buess Posted - 12/29/2004 : 12:50:30 PM
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

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