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
 Find number of rows per column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

psgst

UK
Posts

Posted - 10/09/2006 :  10:19:08 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I want to cycle over several columns in a for-loop (which I have), but for each cycle (each cycle = processing 1 column) I want to find the number of rows containing data in that one column. Is there a function that does this?

psgst

UK
Posts

Posted - 10/09/2006 :  10:31:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
In fact, I'll post my block of code here because I'm not sure if its going to work properly, and could do with some feedback on it. I can't test it myself until I know how to find the number of rows. Basically I've got a worksheet of binned data, and I'm trying to find the frequency by percentage to plot, so I'm looping through each row in each column and placing its percentage value in another worksheet, then I will plot my graph from the worksheet percWks.


window -a percWks;
for (mm = 1, mm <= nCol; mm++) // for number of columns
{
sum(%(binWks,mm));
colSum = sum.total;
nRows = // how do I do this?!

for (nn = 1, nn <= nRows; nn++) // for number of rows
{
percWks_$(col($(mm)[nn])) = (binWks_$(col($(mm)[nn])) / colSum) * 100;
}
}


Is this code valid?

Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 10/09/2006 :  2:25:24 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If column mm contains no missing values you can get the row count from nRows = sum.n. You code looks fine but vector math is much easier and quicker...

window -a perWks;
for(mm=1; mm<=wks.ncols; mm++)
{
sum(%(binWks,mm));
%(percWks,mm) = 100 * %(binWks,mm) / sum.total;
}

Mike Buess
Origin WebRing Member
Go to Top of Page

greg

USA
1379 Posts

Posted - 11/08/2006 :  09:50:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If you have many columns or there are very many rows in the columns, you can speed up the process by just using the GET command :
loop(ii,1,wks.ncols) {
get wcol(ii) -e last;
type Column $(ii) has $(last) rows.;
}


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