Why I love Matlab

Preamble: I love programming in Matlab, though I definitely consider myself a cognitive psychologist/neuroscientist first and programming is more of a tool to accomplish my goals. That said, this is inspired by Olivia Guest’s blog “I hate Matlab: How an IDE, a language, and a mentality harm”. I should also acknowledge that I am approaching this topic from a biased viewpoint, where I do most of my programming in Matlab and have previously written a book on An Introduction to MATLAB for Behavioral Researchers (2014, Sage Publications).

Matlab has a GUI with many features. This can be useful for having an idea of the variables in your workspace and having a code editor window alongside your current workspace interactive environment. In this GUI, Matlab also allows you to edit variables in a spreadsheet-like editor. While this feature is there, I agree that it’s a bad habit to edit variables this way. It could be argued that ‘then the feature shouldn’t be there!’. Well, maybe, but I also think it’s important to have some guidance when learning to program in Matlab (ideally a colleague with more experience, or at the very least an online course or book), and it’s unfair to solely rely on the program’s front-facing features to lead skill learning. When I teach Matlab, I don’t use any of the GUI features — no variable editing, no use of the plot editing tools. Just because the feature is there doesn’t mean we have to use it, but I’d rather have more features than less.

I use Matlab on the scale of 10–20 hours a week (on average), but I also use a variety of other programming languages on a weekly basis, including Python. An important consideration is what you want do within that language. For cognitive neuroscience research, Matlab can be a great boon because of toolboxes like SPM (for fMRI) and EEGLAB (for EEG). While these can be used without much programming ability, being fluent in Matlab allows you to ‘look under the hood’ and get a much better idea of what they are doing, and how some of the code can be adjusted to give you access to some of their inner variables.

Matlab has also been useful when writing code for analyzing behavioral data, as Matlab is designed to be worked with interactively. Admittedly, this can lead to spaghetti code, but that’s where having some training in documenting and structuring your resulting code is important in building reproducible analysis pipelines. I initially used Python before Matlab, but I abhorred that I couldn’t actively work with my code and write blocks of code ‘live’ before committing them to my scripts and functions. This has since issue in Python has been somewhat mitigated with the advent of IPython and Jupyter, but this is an example of where having a company behind Matlab is a strength. Python is developed by many groups of interested volunteers. In contrast, Matlab is developed by a company, leading to a more comprehensive approach to feature development (e.g., integrated plotting functions, rather than separately using matplotlib and then seaborn on top). There also is more naming consistency across toolboxes within Matlab, because there is a company behind it to manage development across the varying teams.

When comparing different programming languages, there are undoubtedly features in one that aren’t in another. I think Matlab is good at providing a flexible space to work within — for instance, generally Matlab does not allow for multiple externally accessible functions within the same file, but there are easy workarounds to this that can be found within less than a minute of searching. More broadly, an important question is: how much programming skill should a cognitive psychology/neuroscience researcher have? As my own opinion, I don’t think they should be doing their analyses in a spreadsheet program, but I also don’t think they should be required to have the skill to develop an analysis toolbox.

Part of my affinity for Matlab is that I generally find it’s syntax more intuitive than I do for Python or R. While I do love Matlab, I’m not beholden to it, so I am also excited about other languages that adopt a similar syntax, though are earlier in development and have a smaller user community, such as Julia.


This blog was written inspired by Olivia’s blog, and not as a direct response. There are some topics that she brings up that I chose not to comment on here, for instance that Matlab doesn’t have a formally-specified grammar and can change aspects of the language with a new version — perhaps I simply do not see the problem with this as I was not formally trained as a programmer, I also don’t follow the issue with indexing counting from 1. While Matlab is closed source, much of the internal code is readily viewable, and I clearly do not see using Matlab as an ‘unethical’ act.

Christopher R. Madan, PhD

Written by

Assistant Professor at the University of Nottingham, Psychology. Computational cognitive neuroscience. Memory; motivated cognition; brain morphology.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade