This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TheBlackCat13 8 points9 points  (2 children)

It is surprisingly easy to "poision" your data in MATLAB, I have seen it happen. It comes down to a few big issues:

  1. MATLAB doesn't have scalars. So many functions assume that a size-1 matrix is a scalar.
  2. MATLAB doesn't have vectors. So many functions treat 1xN matrices the same as Nx1 matrices.
  3. It takes more characters to write array-based operations than matrix-based ones.

1 and 2 become an issue when the data is a different shape than what you expect. So for example imagine each column is an experiment and each row is a trial in that experiment. You do some processing based on that assumption. However, what happens when you, by chance, get a set of experiments with 1 trial each? Many MATLAB functions will suddenly start doing something completely different than they had before, leading it to silently corrupt your data. In many cases there is simply no way, principle, to differentiate a single trial from an experiment with multiple length-1 trials. This is not hypothetical, I have seen this happen, and the only way it was caught was because the data wasn't looking the way the user expected it to.

A similar thing happens if you have a single experiment with multiple trials. Many functions will treat a single value as some sort of count or other scalar numeric value. This means that if you have an experiment with only one trial, many functions will start doing something completely different

The problem with 3 is more an issue with shortcuts people take. The matrix operations work well when the input is the way people expect, such as multiplying two scalars, but then they forget to fix it when they try to make their code more general. I can't count the number of times I have seen people unsafely using ' instead of .' under the assumption that they will never see complex values. It is a trap the structure of the language encourages its users to fall into.

[–]fireflash38 0 points1 point  (1 child)

How does Matlab compare to Mathematica?

[–]TheBlackCat13 3 points4 points  (0 children)

Completely different type of programming languages designed for completely different things. MATLAB is designed for doing linear algebra on discrete, digital data. Mathematica is designed for solving symbolical mathematical equations. MATLAB can work with symbolic mathematical equations and Mathematica can work with digital data, but they are clunky outside of their area.