File Exchange

image thumbnail

Code Metrics

version (67.3 KB) by Santosh Kasula
Generate code metrics for the specified directory


Updated 01 Sep 2016

View Version History

View License

CODEMETRICS computes the same code metrics that the File Exchange displays for all submissions. It allows you to see your metrics before submitting.

Cite As

Santosh Kasula (2021). Code Metrics (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (133)


Neil Judell

Is there any way to get source that generated the MDF executable? Will not run on Windows x64 8.1, even with current copy of cygwin1.dll...

Quy Phan

I happy

per isakson

CODEMETRICS reports one clash for each file in my test. Is that behavior intended? Anyhow, I replaced

% Locate.
clashname = which( fname );


% Locate.
if isscalar( which( fname, '-all' ) )
clashname = '';
clashname = which( fname );

in the subfunction, getClash. Now it reports no clashes in the same test.

Thomas Vanaret

Note : "Filename Clashes" metric is incorrect because it is based on Matlab "which" function WITHOUT "-all" option (private\generateStats > getClash - line 381).

Thus, it does not detect if the function name match many one in the Matlab Path.

Dan K

I have used this utility for quite a long time and really found it to be wonderfully useful. Unfortunately, it no longer works with the updated FEX format. I would be very grateful if it could be updated to work with the new FEX. One other functionality piece which would be very nice would be to have a summary of downloads page, which allowed one to easily see which of the fxdownloads are on the path, which are not, and to toggle the state of any given one. Thanks,

bilal saeed

nice man

FU Kechang

manzoor ahmad

i want to work on fhss

Oleg Verbitsky

ahmed salim

Tobias Kaulic

Hello I'm Tobias
I download your zip File. But when I klick on the exe File, come the Display, that one dll File not found. What kan I do??
I'm a German :)

ender karazeybek

it is necessary to my project.

gill gill


tisa selma

it's great!

kisalay choudhary

moumen ala

sure geo

it is realy useful to the beginners

hussain ghf


novia larasati

baqer soltani


liu yue

y jiang

Minh Nguyen

chetana prakash

Really it is good and helpm a lot

kin dhameliya

very good

hasan sadikin

very good

venkat kanal

very good

Theodosius Zaxaruck

zine leila

please can you tell wich version of matlab i must have in order to use turbo code in simulink

Sakkayaphop Pravesjit

Thanks, this is really useful for keeping track.

chabane fouad


G Brown

Thanks, this is really useful for keeping track.

lekshmi nair



quyet pham


Frank Koch

Qureshi Irfan

Fine Effort

zevallos luna


Mansoor Ahmed

john rob

Gurmohan Singh

gh deng


farzaneh asad

Joung minho

thak you

Yuntao Ju


Sang David

Thank you very much, but I desire to know its corresponding references.

akram daneshmand



he zhi


vinay bhardwaj

ricky127 deh

skjwhjskakahdkadhajkdhajkdhakdj ajkdehajkdhajkashadshakdhakdhkadh akjdhkajd kd akdkadkajd jkdjkd ajkd kdhkd hs

irfan fiaz

its fine

henry wang

very good

somaieh jokar

yong teen yih

liao susu

It is very good!

navid samimi

if may, you send this file for me.
i need for one research

abdul mukti

this good file, and very important to reads

mohamed khatan

Mohammad Hassan Dinpajooh

Not bad

mobile mobilee


mike s

I got an error, then I fixed the proxy server and it is working great. I still have to be smart enough to put in the right search string...

xia tian

Tuan Anh

Verry help full

Gnanasekaran Thangavel

still I have to do more on this

ert ert

fadela sabry

this project is very excellent


tilak kumar

jesada sartthong

yu xue

saied emgary

Excellent Excellent

Mike Oldfiled

souhir mansouri

no comment

Ged Ridgway

The "help warnings" section of the code metrics penalizes me for having no "example" section in a Contents.m file and in a demo.m file that exists solely for the purposes of producing a published m-file (which is *all* example!)

I wonder if Contents.m should be checked separately (as in the "contents report" on a directory). And I wonder if it would be possible to skip/relax checks on blah.m if blah.html is also present in the zip?

Thanks for a useful tool.

ams mas

Jeremy Steveson

Thanks for providing. Please provide an intel r2007a mac version of the compiled windows & linux app for the dup code art of the metric.

While any metric isn't perfct I need to manage a large amount of code from many coder and this helps me get a first pass at code I need to look at.

Thanks again.

cecil hoarau

je cherche un logiciel pour tabler des commande, et pouvoir me servir de procedé de mathlab.thank 's very much.

pari pari

very good example explain

Lizbeth Paredes Aguilar

I would like, to acoupled of the toolbox fuzzy with comandes matlab, into to simulink for the desing fuzzy control process.

Hung Tran Khanh

Could you tell me the way to generation a numer using the Gaussian random is, please?

varun bharadwaj

igor psychotron

rahul chowdam

Bishwajit Aich


senthil kumar

Jahanzeb Rajput

It runs on MATLAB 7, how can it check the metrics of the m-files generated using oler versions of MATLAB correctly?

mojtaba mahdavinia

i am student university sharif.i want formations related simulation bldc.thnks

abrham Hailu


Liyth nissirat

it is great

Bashir Bala

very good,and excellent

kamatchi priya

mohamed fazal

excellent one, improve it...

sathya niranjan

good one... keep it up

Hung nguyen

very good

egdy za

wilmer salazartrujillo

necesito un ejemplo de simplex en matlab

wilmer salazartrujillo

necesito con urgencia el desarrollo de un problema de simplex en matlab.

indu a

Good it helped me a lot

maria arrabal

C. S.


chandan chandan maity

very good

Brian Hui

It is pretty nice. However, when I used it, the one it downloaded is not the one I picked. There is one file shift between them. Is it just me or everyone gets this problem?

suresh t

ibrahim oudjani

I need a matlab code for face detection.thenk's

azam gholizadeh

i want transmit nmr spectrum in matlab help me

azam gholizadeh

reza sahebi

its very good

Muhammad Farrukh Subhani

I am getting following error with todays download (4/10/2006)

??? XMTOK takes one input, one output.

Error in ==> Improve Codes\private\generateStats>getLineCounts at 83
[unused,bptok] = xmtok(f);

Error in ==> Improve Codes\private\generateStats at 29
[stats(i,1).lines,stats(i,1).comments] = getLineCounts(file);

Error in ==> codemetrics at 31
stats = generateStats(workingDir);

duojia chen


oudjani ibrahim

Ronny Meza

Animesh Gain


arun gk

namnam namnami

kunle oni

hi i got your mail on the mathlab central and i will like to know you

Satyanand singh

Really it is good.I wish you all the best

Celalettin Yýlmaz


I don't find this to be particularly useful myself, but it is worthwhile code to have around.

We seem to have a lot of whiners here. THIS IS FREE CODE PEOPLE! IF YOU DON'T LIKE IT, DON'T USE IT!

This code is on the File Exchange for free. It's not part of a MATLAB Official Release, and is not held to the same "high standards". I can write any peice of garbage code I want (not that this code is garbage) that is useful to someone out there and post it here at the File Exchange. Geez... you didn't just pay $1k for this code, so stop feeling as if this code should be tailored specifically to your liking.

BTW, I found this code easy to follow when reading through the *.m files, but maybe that's because I actually understand MATLAB, unlike *some* people.

teena joseph

I would like to know how an image can be loaded in the Matlab prompt

Norbert Marwan

Does not work on a system running another OS than MSWindows, because it contains a compiled programme. The advantage of Matlab is, I guess, that scripts, functions and toolboxes are working on every platform, independent on the OS, isn't it?

Moreover, I fully agree with Oliver.

Oliver Chapman

On one hand, I can't complain too much, the code appears to do what it is suppose to.

But, particularly a ~15 module function should be written such that it is easy to tell what it is doing and how.

It took me 45 minutes to dig down to discover the undocumented feature in "mlint" that calculates complexity.

This code doesn't even pass that test with an index of 13.

Each module should have a summary of which modules it calls and who calls it. Variables should be defined. Spaces should follow commas.

All these points, and more, are covered in the Style Guidelines in your White Paper section.

This looks like cowboy code and I've wasted too many years digging thru this type. It really is cheaper to write it well first, from well written requirements and with quality documentation.

If MathWorks employees write this style of code, how can I be assured the primary functions in MatLab are well written?

Matthew Simoneau

Eduard, it should now be doing the right thing with respect to methods. Let me know if we're still missing something.

Urs, mdf is compiled only for Windows, and now Linux. On other platforms the report won't be able to include "cloned code", but the rest of it should work. We're looking into opening the source code for this, but it dives into parts of the parser to find equivalent code (even if it's not identical) and we need to be sure we're not revealing any trade secrets.

Darren, yes this code will only run newer versions of MATLAB. It uses some experimental features that were only introduced recently.

Heinrich and Dave and John, we relaxed the regular expression we are using to detect examples. plot4 will now be OK.

As to the value of these metrics, nobody is claiming that they are the ultimate judge of quality. They are just here to suggest areas where your code might be improved and to show how any submission compares to others on the File Exchange.

Thank you all for taking the time to send your feedback and please keep it coming.

Jiro Doke

I tried to improve the score on some of my m-files using this, and ultimately decided that there's not always a direct correlation between good code and good score, as many have mentioned here. I think it would be useful if the SCORE and PERCENTILE RANKING were removed. These are often subjective, so assigning a number to the "goodness" may not be the way to go. However, the raw results from each criteria may still be helpful (the example check should be improved). Then based on those results, people can make their own judgement on the usefulness of the code.

John D'Errico

Looking more deeply into these metrics, I note that cyclomatic complexity penalizes better codes. A comparison of two codes which are identical, except that one has extensive error checks for bad data, will yield a poor complexity score for the code which attempts to check for problems. Every test for problems should reduce the resulting score. I wanted to verify this fact, but I cannot since this submission only runs if you have PC matlab. Sigh.

John D'Errico

I'm lukewarm about these metrics. These are not perfect at all, but they can be improved. Any single number measures of code will tend to show only the broad tendencies anyway. And they can easily miss subtle variations, for example, in how an example is flagged. Your examples may get missed just because of use of the phrase "example usage", instead of just "example".
Mlint is another problem, since mlint in the newer releases will catch more problems in your code. Since these metrics will use our own (sometimes older version of) mlint, they need not be even truly representative of the website metrics.
As for cyclomatic complexity, I can't even pronounce it. ;-) But it does seem ironic that "code metrics" got a poor score itself for cyclomatic complexity.

Robert Finch

I personally find this submission to be a wonderful addition to the FEX. Be able to quickly see the number of lines of code and % percent of comments on a directory of code is wonderful. Anyway who manages a large number of matlab programmers will see the benefit of having this available. As for those that hate metric, think of it has a relative thing. If you see someone consistently with little comments, then you need to check it out and see if their comments are on par. Let's not think in absolutes.

Duane Hanselman

For folks who write good code, these code metrics are not much use. However, they do identify poorly coded submissions. Folks who don't bother to check mlint messages or care about name clashes get flagged by these metrics. The "cyclomatic complexity" metric is the one I don't fully understand. Sometimes it just isn't possible to get a low (good) number.

dave martin

As stated before, this metric misses things, like examples for example. I hate programs that purport to tell me how to program better anyway.

Heinrich Acker

I did not run this submission, but looked at the results for other submissions. It produces wrong results sometimes for the help section. For example, look at the comments of the recent 'plot4' submission. It has an example, but code metrics tells it hasn't.

Darren Engwirda

Doesn't seem to work on R13. Problem with regexp and 'Tokens'...

I agree with Us. Codemetrics suck. They don't measure anything useful and can give the impression there is something wrong with a submission when there isn't.

This is not an attack on the author, I'm sure your submission does exactly what it says it does for R14.

urs (us) schwarz

the core (mdf.?) is hidden - and this is simply very insulting and just a no-go to this community!
personally, i am extremely disenchanted by this submission - as i have been very disenchanted by the recently introduced file/code metrics to begin with since it is:

- absolutely (sic!) useless in the realm of ML if ever you understood anything about its visionary concept...
- promotes mediocrity (sic!) at best... that is: at best...
- most of the time computes, extracts, and displays plain false, inscrutable, mostly unintelligible, and absolutely misleading information (particularly for a newcomer) about a contribution

as i said: i am VERY disenchanted

Eduard van der Zwan

This is just what I was looking for. Just one quation. Under filename clashes it only shows the clashes with the functions them selfs e.g. gravity.m: work/unitfun/gravity.m and not the real clashes e.g. for @foo/vertcat.m. Should i perhaps change my path or is this a bug?

MATLAB Release Compatibility
Created with R2006a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!