About

This blog is all about why you should not use MATLAB. I’m stating it as plainly as I can: Unless you have no other alternative, you are better off picking something other than MATLAB for your scientific programming needs. And there is always an alternative.

I feel about MATLAB pretty much the same way Steve Yegge feels about Perl. The parallels are numerous and uncanny.

4 Comments

  1. Jim said,

    Hi,

    Here’s a bit of matlab output that may surprise you.

    >> x
    x =
    100
    >> y = 400;
    >> z = x + y
    z =
    127

    You’ve probably guessed what is happening. x was defined as type int8 and has caused z to be cast down to int8. Does any other language do this sort of thing? Is this a well known feature of matlab?

    Feel free to invent much more complicated examples. I spent days trying to debug my code before I did a “whos” that showed that I had a very large collection of int16 values. It was all caused by one int16 scalar that resulted in lots of derived numbers becoming int16.

    • crowding said,

      Yeah, MATLAB’s numeric type hierarchy is completely backwards, every operation with two types is cast to the less accurate type as result. It’s completely the inverse of what every other language does. I kept trying to write a post detailing this but kept boggling — how do you explain that a tool has been constructed, not merely without forethought, but with malice aforethought? That the designers of the language sat down, considered the options, and chose the WORST POSSIBLE of all possible ways to do things?

  2. Aurélien said,

    whos is one of the first command that you learn as a MATLAB beginner. I am surprised that you didn’t understand the “127″ behavior whereas you know the int16 or int8 command. It is definitely a great feature to save memory when you know the type of data that you are using.

    • crowding said,

      The original reason integer data types were introduced in MATLAB was to save memory for signal processing or image processing functions. This is why they chose the weird saturating-add behavior. But if you look at signal processing or image processing toolboxes do today, you’ll see that they all insist on using doubles. This is because MATLAB’s broken backwards numeric type hierarchy caused more problems for users than it ever solved.

      In reality, the only function of saturating arithmetic is to disguise overflows. If you actually give two whits about your data, arithmetic overflows ought to raise red flags all over the place. What MATLAB does is make its mistakes as silent and invisible as possible. Data in, garbage out.

      Sometimes it it useful to restrict the range of a type in order to save memory. Most languages let you do this sensibly. Hell, even C and Fortran will do it sensibly. MATLAB’s approach is worse than useless and causes nothing but problems.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.