I’ve used MATLAB almost ever single day for the last year, and I can say confidently that two things are true of MATLAB:

- Every engineer has used it.
- No engineer likes using it.

Certainly, there are lots of great things about MATLAB – and MathWorks would be glad to tell you what they are. So instead, here goes with my top 5 reasons for hating MATLAB.

### Reason #5: MATLAB arrays are 1-indexed instead of 0-indexed.

If you’ve ever programmed in a ‘real’ language (C, C++, Java, javascript, etc.), you know that to access the very first element of an array named `x`

, you would index at 0, i.e. `x[0]`

. To iterate over all the elements in an array with *n *elements, you would proceed from `x[0]`

to `x[n-1]`

. Simple, easy, great in `for`

loops.

MATLAB? No. Supposedly because mathematical arrays are indexed from 1 to *n*, MATLAB uses the convention that `x[1]`

is the first element of the array. (In fact, in MATLAB, you’d have to use parentheses instead of braces, but I’ll get to that in Reason #4.) So to iterate over the set, you start at 1 and stop at `n`

.

Doesn’t seem like such a big deal, right? Maybe not to someone who only codes in MATLAB (or R, which uses the same convention), but if you’re like me and spend a lot of time programming in C++ or Java, it’s absurdly frustrating. It’s like going back and forth between QWERTY and Dvorak keyboards – each time you switch, you make a lot of mistakes getting re-adjusted.

### Reason #4: inconsistent interpretation of matrix indexing

To access array elements in C, C++, and Java:

elementIwasLookingFor = x[index]

To access array elements in MATLAB:

elementIwasLookingFor = x(index)

Why parentheses? Great question. I’m still waiting to hear the reasoning on that one.

### Reason #3: poor concept of objects

The dominating paradigm in systems programming nowadays is, of course, object-oriented design. And sure, MATLAB supports really basic struct-like objects – for example,

`object.property = value`

But what about objects that can *do* things, like set private members, intelligently update and return values, and other cornerstones of OOP? Negative.

“But MATLAB is just an interface on top of C! You shouldn’t need objects in MATLAB!” you might say. Fine, I shouldn’t be building huge systems in MATLAB. Or should I? With tools like SimuLink and the Image Processing Toolbox, objects would make total sense, especially given that sometimes I would like to add functionality to the object without rearranging all of my code. That’s what OOP does, and why it sucks that MATLAB doesn’t support it.

But that’s all popcorn compared to my real complaint. I love programming in other languages for a really simple reason: auto-complete. On 90% of occasions, I forget how I spelled that public member function, and auto-complete saves me about half an hour of search-for-the-name time on a daily basis. But since MATLAB doesn’t understand objects, it can’t auto-complete those functions, meaning you have to look up how it’s spelled/called. Ridiculous.

### Reason #2: String handling

Have you ever tried to concatenate two strings in MATLAB? Then you know how much it sucks. In most languages, you can type

String result = "I go to " + "the store"

and you’ll get

result = "I go to the store"

In MATLAB, though, the strings are treated as arrays of characters, such that adding two strings is the equivalent of adding two numeric arrays. To *actually* concatenate the strings, you have to use a kludgy piece of ridiculousness like the sprintf workaround:

result = sprintf("%s%s", "I got to ", "the store")

It’s just one more thing that makes good reporting and text formatting nearly impossible.

### Reason #1: they didn’t even write their own math engine!

Engineers use MATLAB primarily due to its fast, robust, effective matrix operations. Even with 1,000,000 x 1,000,000 matrices on a weak Acer PC like mine, MATLAB can crank out matrix products, singular vector decompositions, exponentials, and the like without even breaking a sweat. It’s great! The problem is, we don’t have MATLAB to thank for that – the credit belongs to the free, widely distributed, available-for-immediate-download LAPACK.

So with that, even MATLAB’s most essential feature set isn’t a unique advantage. We engineers put up with a lot of MATLAB’s inconsistencies and faults, just to get access to LAPACK without needing to use FORTRAN.

Personally, I’m eagerly awaiting the day when the very MATLAB-like (but free!) Octave or the statistics-focused (and also free!) R have enough of a following to become industry standards in and of themselves. But until they do, the majority of code examples, training, and industry expertise will remain trapped in MATLAB, the Microsoft Windows of mathematical computing and simulation tools.

Every programming language has syntax quirks, and string handling is much harder in C.

And Octave does the same thing as MATLAB – it is using LAPACK and it has the same syntax minus the object parts.

You can try Scilab (with its own quirks) or NumPY.

LikeLike

you should definitely switch to the python based stack of numpy/scipy/scikit and all surrounding libraries. they give you convenient access to all kinds of c/c++ and fortran code without even noticing it. e.g. install python(x,y), sage or even EPD to get rid of all of that.

LikeLike

Hi harri, thanks for the comment – great suggestion about numpy and scipy. I’ve actually been using numpy for the past several months now, and really like it – especially the plotting functions.

LikeLike

Why would you think 0 based array indexes are better, besides the fact that it’s used in some other programming languages(C, and C-like mostly)?

In my opinion 1 based array indexes are better because they are how humans think.

LikeLike

Having 1 based array means that somewhere, at runtime, there’s always a -1 to match the memory model of the calculator, that is zero based. This is a constant performance hit, which can’t be removed. 1 based arrays have the semantical advantage that index of the last element in an array is the count of the elements, but 0 based arrays have the semantical advantage that count of the elements is also the next index in the sequence, which is often meaningful when writing algorithms.

LikeLike

It’s not that 0-based indexing is “better” – it’s that MATLAB is wholly inconsistent in applying it for all situations. For example, arrays use the ordinal “1-indexing” but when you set up a loop counter, suddenly you need to think in terms of cardinal “0-indexing”. Python and C++ keep consistent standards across the board, so this is just one (there are many more) example of how MATLAB creates an unwise, counter-intuitive nuance that really doesn’t serve a purpose.

Generally speaking, it seems like MATLAB’s “language” was developed by 15 different people with 15 unique perspectives on what the syntax should be…rather than intelligently unifying the standards, MATLAB instead just asks us to learn 15 different syntaxes for the same thing.

At the same time, I can’t think of one “MATLAB-ism” that isn’t completely trivial. It’s like those people who read your paper, change a single word, then walk around claiming credit for the whole thing because they “added originality” to you work.

One poster already said it – strip away the modules, and all you really have is a nifty library of matrix calculations, and one that has been long supplanted by better stuff. MATLAB is basically a report-stealer – making insignificant, minute changes in order to claim that theirs is a unique “language”. The problem is that everyone’s been using it for so long that they don’t want to take the trouble to change…that, and the modules aren’t all bad. Especially since they don’t involve a lot of “programming” in MATLAB’s “language”.

Whew.

LikeLike

1) By way of example, here is how to concatenate strings: [‘String 1’ ‘ String 2’]. Honestly, I’ve met a number of people who work there. They’re pretty clever guys. If you assume that the answer exists, then it probably does, and you’ll find it in 5 minutes. If you assume that it does not and, subsequently, never look for an answer, then you’ll be disappointed. But then, I think that applies to any language.

2) Objects are supported (at least, to the extent that you desire).

3) Everybody uses LAPACK. You’d be an idiot not to. Also – and you can’t be faulted for this, even if I were inclined to do that – Cleve Moler (a co-founder of MATLAB) worked on LINPACK/EISPACK.

So, actually, they _do_ get some credit for your last point.

LikeLike

LookTwiceCutOnce – great points, thanks for posting.

LikeLike

http://matlabnstuff.blogspot.in/2013/01/controlling-keyboard-switches-with.html

LikeLike

I don’t think your comments about the array indexing notation are fair. It’s very, very annoying, but matlab is an old program that was originally coded in fortran and was meant to be used in domains where fortran was common. And arrays in fortran are indexed starting at 1 and their elements are accessed using parentheses.

Also I believe matlab using the Intel MKL for matrix operations, which is a tuned LAPACK implementation. It’s not really fair to criticize them for using that because writing high performance matrix libraries is very difficult. You need people intimately familair with both linear algebra and, more importantly, computer architecture. The difference between a highly tuned BLAS/LAPACK operation and a naive implementation can easily be an order of magnitude or more. Since matrix algebra libraries are used places other than matlab it makes sense for matlab to just use the libraries written by someone else. Then they can concentrate on making sure their front-end to those libraries works.

Don’t get me wrong, though. I totally hate matlab. The string processing alone is enough to turn off anyone who needs to data analysis, but the expense, it being closed source, lack of decent object support, and just in general not being a general-purpose programming language makes it a very unpleasant experience.

LikeLike

As an experienced C++/C#/Java/Python programmer, who used MATLAB in some projects, here is my main reason for hating it.

Its type enforcement system is seemingly arbitrary, or at least very counter-intuitive to programmers with OOP mindset.

For example, some functions that require double, can accept int and just convert it, but others will give an error. There is no pattern, and can’t be deduced from the function’s signature (you have to either read its code, or google it and see if someone has already read its source and wrote about it somewhere on the internet).

To me, it seems like the worst behavior of strict type enforcement (such as in C++ or Java), mixed with the worst of duck-typing (such as in Python). It makes even javascript look rational and benign.

Maybe it’s because I’m not an expert on MATLAB (though I did use it in several projects, so you can’t say I have no experience at all), but to me, it only shows that MATLAB is not a friendly language, even to programmers who are highly experienced in multiple other languages.

Also, I’ve tried using numpy/scipy in a minor project, and it was great.

LikeLike

brutus – I agree completely. Thanks for pointing out the half-hearted type enforcement in MATLAB that I’d forgotten to mention.

LikeLike

this is because us who love matlab hate OOP or anything coming from ‘comp science’ world as much as you hate matlab, for exactly the same reasons.

matlab was intended to be floating 64 everything. types came as an afterthought. but I don’t need any types. i’d rather stick to matlab version 4 or even before than having to deal with anything ‘comp sci’ related, including ‘methods’ and similar. Or xml (what a nightmare/mess). I wrote my own code in matlab to find what i want in xml, rather than wasting time learning the ridiculous structure and logic of xml. geez, it is so bad it hurts. it is all a stream of bytes, coded in 8 bit in the end. A simple code to detect a string I am looking for is certainly much better time investment than learning yet another ‘protocol’ ‘invented’ by someone, that will be obsolete in 5 years because another thing will come up that is hot.

Another example of how ‘computer science’ majors are causing much more pain than help – a myriad of equipment communication protocols for industrial equipment. Geez! It is getting ridiculous. It used to be rs232 to rs232 equipment. Turned into rs422/rs485 for obvious reasons. gpib was an alternative, but too expensive in cabling etc. but then, surely everyone and their dog felt the need to write a new ‘protocol’. just look at devicenet. this is a typical example of why ‘computer science’ should be shot dead. built on wrong principles and ideas, every ‘comp sci’ graduate will have this mindset, not knowing better. he will be employed somewhere, and eventually he will force his logic to the structure, backed by others from the same background. The end effect is, I am controlling a chemical process with a valve – the valve needs at most 5-6 commands – set point, PID parameters, and pressure/position mode control switch. at most 10 commands. but no. I get this new valve from a reputable company. it is on devicenet. ok no problem. until i need to program it. turns out, it has 2000 pages or so manual. methods, datatypes. redundancy. I can access the same function from 18 levels of ‘abstraction’ (all terms to make comp sci majors feel more important than they are). then i open an old valve and send three commands (similar to G code for cnc), V12.0, I0.5, M1.0 etc., and I am finished.

No offense, but ‘comp sci’ should be banned from universities as a major.

LikeLike

I liked your article

LikeLike

I agree most of this (ESPECIALLY the parentheses reference to array elements), and hopefully Python with numPy and various packages will become the most popular in my field soon.

However that’s the wrong way to concatenate two strings. Much easier is this: [str1 str2], i.e. implicit array construction. Not much more work than str1+str2. The “everything is an array” structure of matlab is actually the thing I like most by far.

LikeLike

Pingback: Monday, November 16th, 2015 | Reverie and Rumination: Constructing a View

python is the superior programming language, I have written numerous programs in Matlab that by all accounts, should work, and for a variety of reasons, some of which remain unknown, they do not function as they should.

LikeLike

Five years later, and R is in the top five programming languages. Very nice!

LikeLike

Thanks for the catharsis. Having been forced to use it I hate Matlab with a passion for all the reasons you’ve mentioned, but also because of the poor documentation (which was eluded to by one other commenter). Also the Matlab Answers. You go looking for anwsers as to why your stupid code isn’t working and more often than not you find a snarky comment from Jan insinuating that someone else doing the same thing is an idiot.

LikeLike