MATLAB programming best practices

I'm looking for resources on how to structure medium- to large-scale MATLAB projects, especially ones that involve several independent modules. How do I manage global configuration variables, how do I structure the project into folders, how do I manage couplings between modules, etc.

Is there some kind of standard text on this subject? It looks as if most MATLAB textbooks have been written by scientists or engineers. What I'm looking for, I guess, is any MATLAB textbook written by a software engineer. :-)


MATLAB is an unusual choice for a large-scale projects and is as much suited for such task as assembler, COBOL or SQL. If you still choose MATLAB then at least automatically test the code! All kind of tests - integration tests, unit tests, load tests! And of course use a version control system.

As said, MATLAB was not created with large projects in mind therefore the only best practice regarding project structure, modules, coupling is the common sense.

If you are taking over an existing large MATLAB project then I am sorry with you, refactoring will be nightmare. If you are going to start a new large project with MATLAB then you are crazy - there are much better alternatives to MATLAB that are not that bad regarding numeric performance. Large project implies that almost all code is business logic, not numerics, therefore why for God's sake MATLAB?

Large project implies well structured components, which implies OO, which is the weak point of MATLAB because it sacrifices heap performance for numeric performance to the degree of unusability.

My experience:

  1. I spent years in in a half-million LOC MATLAB project.
  2. I have seen painless transition of multiple large MATLAB projects to C#.

With MATLAB you still have to use large amounts of Java for decent looking GUI, C/C++ MEX for fast not numeric parts like imports, maybe SQL, etc. With Java (or better C#) with a free numeric library you have only one language which is perfectly suited for everything you need in a large project.

I am not saying that MATLAB is bad - it rules for rapid prototyping and numerics! And Simulink has no alternatives (but can be compiled and used from everywhere).

You may want to have a look at "The Elements of Matlab Style" (review by Loren Shure).

Also, this review of good coding practices might be useful.

Need Your Help

Finding # occurrences of a character in a string in Ruby

ruby string methods

I'm looking for the Ruby method (1.9...) that can help me find the number of occurrences of a character in a string. I'm looking for all occurrences, not just the first one.

Elegant grid search in python/numpy

python numpy

I have a function that has a bunch of parameters. Rather than setting all of the parameters manually, I want to perform a grid search. I have a list of possible values for each parameter. For every