Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good practices in writing MATLAB code? [closed]

People also ask

How do you make MATLAB code more efficient?

Two effective programming techniques to accelerate your MATLAB code are preallocation and vectorization. With preallocation, you initialize an array using the final size required for that array. Preallocation helps you avoid dynamically resizing arrays, particularly when code contains for and while loops.

Is MATLAB closed source?

Secondly, Matlab is closed source, proprietary, and prohibitively expensive if you have to buy it yourself. They obfuscate their source code in many cases, meaning bugs are much harder to spot and impossible to edit ourselves without risking court action.


Read Code Complete, it will do wonders for everything. It'll show you where, how, and when things matter. It's pretty much the Bible of software development (IMHO.)


These are the most important two things to keep in mind when you are writing code:

  1. Don't write code that you've already written.
  2. Don't write code that you don't need to write.

MATLAB Programming Style Guidelines by Richard Johnson is a good resource.


Well, if you want it in layman's terms:

I reccomend people to write the shortest readable program that works.

There are a lot more rules about how to format code, name variables, design classes, separate responsibilities. But you should not forget that all of those rules are only there to make sure that your code is easy to check for errors, and to ensure it is maintainable by someone else than the original author. If keep the above reccomendation in mind, your progam will be just that.