Skip to content

Clean code workshop: MATLAB#

This workshop aims to show some good coding practices to use with MATLAB.

Even though the examples rely on MATLAB code, this contains a lot of very generic rules that are language independent and that that will work equally well, whether you are coding in MATLAB, Octave, Python...

Requirements#

Please make sure you have the following installed on your computer before the workshop.

MATLAB#

  • It does not need to be recent version.
  • Let me know (by opening an issue) if you need access to a MATLAB license for the duration of the workshop.

MATLAB toolboxes#

Those 2 MATLAB toolboxes will help with running tests and code coverage:

Note

Recent versions of MATLAB also have their own testing framework. But I will not use it in this workshop.

GIT#

  • command line or GUI: whatever you prefer! 😄
  • a gitlab account (the one from your university is probably fine).

To make sure you are set for the workshop, please make sure you can fork this repository.

Code editor#

Install VS-code as a proper code editor will be useful when working with files that are not MATLAB scripts or functions.

VS-code extensions#

VS-code has many extensions. Two that may be useful:

  • MATLAB allows MATLAB syntax highlighting.
  • error-lens highlights errors in the code.

Python#

  • For example installed via conda.

Python packages#

  • miss_hit for MATLAB code style checking, formatting and linting
pip install miss_hit
  • pre-commit for applying code style checks before committing
pip install pre-commit

Sample code and data#

If you do not come to the workshop with your own code, you can use the sample code and data provided in this repository - see the folders code (on gitlab or github) and data (on gitlab or github) .