Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB programming best practices

Tags:

matlab

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. :-)

like image 862
lindelof Avatar asked Feb 18 '11 14:02

lindelof


People also ask

Is MATLAB good for programming?

MATLAB is a high-level programming language designed for engineers and scientists that expresses matrix and array mathematics directly. You can use MATLAB for everything, from running simple interactive commands to developing large-scale applications.

Is MATLAB coding difficult?

It uses the programming system and language called MATLAB to do so because it is easy to learn, versatile and very useful for engineers and other professionals. MATLAB is a special-purpose language that is an excellent choice for writing moderate-size programs that solve problems involving the manipulation of numbers.


2 Answers

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).

like image 111
Mikhail Poda Avatar answered Oct 05 '22 16:10

Mikhail Poda


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.

like image 36
Jonas Avatar answered Oct 05 '22 17:10

Jonas