When MATLAB Is Better
MATLAB, a proprietary scientific programming language released in 1984 by MathWorks, gets a lot of hate from software engineers online. While I tend to agree, I still find myself drawn to it for quick prototypes and as a tool for analyzing and debugging simulation output. Here is an unsorted list of MATLAB features that keep me using it, despite its odd semantics and high price.
Superior Matrix Literal Syntax
Engineering work requires matrices. MATLAB makes them easy to write. Consider the following matrix:
$$ A = \begin{bmatrix} 4 & 9 & 2 \\ 3 & 5 & 7 \\ 9 & 1 & 6 \\ \end{bmatrix} $$
In NumPy, this is written as:
A = np.array([
[4, 9, 2],
[3, 5, 7],
[9, 1, 6],
])
In MATLAB it is declared as follows:
A = [
4 9 2
3 5 7
9 1 6
];
We have only saved a small number of characters, but when you are rapidly iterating on a prototype, the NumPy syntax gets old fast.
It also helps clarity for inline matrix literals. Compare:
B = A @ np.array([[2,0,0],[0,1,0],[0,1,0]])
And:
B = A * [2 0 0; 0 1 0; 0 1 0];
The sparser syntax cuts through the noise and helps the reader see the math that is being performed.
Simpler Matrix Concatenation Syntax
Matrix construction and concatenation in MATLAB share syntax, much as you might express an augmented matrix in a textbook.
$$ A^{\text{aug}} = [A | b] $$
In NumPy we would have to write:
A_aug = np.hstack((A,b))
In MATLAB it is as simple as:
A_aug = [A b];
More complex matrices can tile easily:
A_aug = [A b; zeros(1,width(A)) 1];
Again, this is a simple change, but it really does speed up the workflow.
Minimum Rank of Two for All Values
MATLAB has no concept of a value that is not an array.
If you type 0.0
into the REPL,
you get 1x1
matrix of doubles. This is not particularly interesting when
it comes to scalars. However, this does mean you will never worry about
not being able to transpose a 1d vector, and extra singleton dimensions
never cause problems (up to rank 2).
Variables Stay Resident After Script Execution
MATLAB's workspace browser shows a list of all variables in scope after your script has finished executing. This isn't much different from attaching a debugger, but it does give you the ability to run a script to generate debug plots, without having to modify and re-run your original script.
Fantastic Standard Library
Ok, I'm cheating and including the toolboxes in the standard library, but if you have MATLAB, there is a good chance your work paid for it, and they paid for most of the toolboxes too. However, it is nice to have obscure things like IMU models, GNSS constellation simulations and the ability to connect to a Bloomberg terminal, all in scope, all the time.
Robust Documentation
MATLAB's documentation tends to include a complete description of the algorithms and equations behind each routine. This helps you build confidence that you are using them correctly, and that they are suited to your purpose. Plus, the documentation can be installed locally and used offline!
One Based Indexing
I mostly included this one in the hopes of getting more engagement on Reddit, thereby getting noticed by MathWorks who will then send me a free MATLAB license. In all seriousness, one indexing is how mathematicians have been doing it since before computers, and it helps when transferring equations from a textbook.
Conclusion
Software is good when it is useful to its users. Many software engineers would prefer this not to be the case. They see good software as having elegant abstractions, mathematical purity and zero duplication. This is often a prerequisite to produce useful software with consistency over time. It is, however, not an end unto itself. MATLAB is an old tool with many warts and strange behaviors. Nonetheless, it is exceptionally useful for turning ideas into running code.
This does not apply to Simulink, unless you are tuning control loops. Please stop writing 6DOFs in Simulink.