Code covered by the BSD License  

Highlights from
COUNTCODE

4.2

4.2 | 5 ratings Rate this file 13 Downloads (last 30 days) File Size: 1.71 KB File ID: #10175

COUNTCODE

by

 

27 Feb 2006 (Updated )

count coded and commented lines in an m-file

| Watch this File

File Information
Description

N = COUNTCODE(MFILE) returns the number of code lines in MFILE. MFILE should be a string containing a name to an existing m-file or asv-file.

[N,M] = COUNTCODE(MFILE) also returns the number M of commented lines in the file. [N,M,S,Q] = ... further returns a cell array of strings S containing all lines of the file (code and comment, but excluding empty lines) and a logical vector Q with ones for the comment lines of S.

Note: this file use <regexp>

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
24 Dec 2009 Pavan

Nice and useful function.

01 Mar 2006 sri harsha boddepalli  
01 Mar 2006 Raymond Norris

Jos-

It looks like your code is checking for the number of lines of text (sans comments), not the number of line of code. Specifically, if a line of code is continued to the next line with elipse (...), COUNTCODE will treat this as two separate lines of code.

Look at SLOC (http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3900&objectType=file) as an example that handles block comments and continued lines. I like your approach (10x faster than mine), you just need to do a little more parsing.

01 Mar 2006 Jos x

An update (with which and total lines) is on its way. Unfortunately, I do not have R14 yet ... Poor me ...

28 Feb 2006 John D'Errico

Not bad, but it needs to count block comments, and the requirement of needing a full path to a file is silly when which will give it that information.

28 Feb 2006 Jiro Doke

Very nicely done. One request (personal preference) might be a capability to run this for any file in the path (instead of having to type in the full path). Maybe if the file is not found, then do a WHICH to see the file exists in another place.

Other than that, good documentation and error checking.

28 Feb 2006 urs (us) schwarz

nice function with good help and sound engine
two minor drawbacks
- it would be nice to get the total number of lines of a file as well (akin to the unix WC)
- it doesn't know - yet - how to deal with block comments (a new r14+ feature)
us

Contact us