Home

Welcome to the MATLAB Programming Style Guide Wiki. If you want to access and search this style guide directly from the MATLAB command line, add the MATLAB Style Guide Wiki access and search function (direct download) to your MATLAB path. If you'd like to contribute, request editing privileges using this contact form.

Introduction

There are many published guidelines available that address general programming and particularly MATLAB programming (see below). This site is designed to build on those resources by tapping into the collective wisdom of the MATLAB user community. The initial content is primarily from Richard Johnson's MATLAB Programming Style Guidelines (used with permission), but the hope is that the user community will quickly add and edit. For a lot more on MATLAB style, check out Richard's book The Elements of MATLAB Style (Loren Shure book review | eBook access for those with credentials).

For now, advice outside of style and readability of your code is beyond the scope of this wiki (but in the future, who knows). There is a lot of advice out there about coding efficiently (if you're into that, check out Cody). This site's concerns are correctness, clarity and generality. The goal of these guidelines is to help produce code that is more likely to be correct, understandable, sharable and maintainable.

Style guidelines for MATLAB are generally the same as those for C, C++ and Java, with some exceptions specific to MATLAB features. The initial content of this site was populated using Richard's guideline, which in turn was "based on guidelines for other languages collected from a number of sources and on personal experience. These guidelines are written with MATLAB in mind, and they should also be useful for related languages such as Octave, Scilab, and O-Matrix."

Keep in mind that everything here is a suggestion. This site is a resource to help you improve your coding practices. If you're part of an organization, you should favor your organizations' style guide over these.

About

This project came about from working with students who work on a small programming work package as part of a student project or thesis. A fixed style guide is quite useful, but some more flexibility was needed both from the instructor side and the student side. A wiki helps with this. Since it's a public university with a mission of moving all of humanity forward, why not make the site public? MATLAB also has a very strong and active user community, and it is hoped that the site may be able to tap into that.

Further reading and references

The Elements of MATLAB Style, Richard Johnson

The Practice of Programming, Brian Kernighan and Rob Pike

The Pragmatic Programmer, Andrew Hunt, David Thomas and Ward Cunningham

Java Programming Style Guidelines, Geotechnical Software Services

Code Complete, Steve McConnel - Microsoft Press

C++ Coding Standard, Todd Hoff

Links and resources

MathWorks

MATLAB Central

File Exchange