What can MATLAB do that R cannot do?

MatlabRScientific Computing

Matlab Problem Overview


I often hear people complain how expensive MATLAB licenses are. Then I wonder why they don't just use Octave or R. But is the latter right? Can you use R to replace MATLAB?

Matlab Solutions


Solution 1 - Matlab

> Can you use R to replace MATLAB?

Yes.

I used MATLAB for years but switched primarily to R in the last 3 years. At this point, they have much more in common than not. It partially depends on your field and use-case. And as http://old.nabble.com/Comparison-between-R-and-MATLAB-td18000568.html">Spencer Graves said previously, it also depends on which "church you happen to frequent". It's best if you look at the http://www.mathworks.com/products/product_listing/index.html">MATLAB toolkit vs. http://cran.r-project.org/">CRAN</a> for a specific task before you decide.

A similar question http://tolstoy.newcastle.edu.au/R/help/04/04/1284.html">asked on R-Help a few years ago and http://old.nabble.com/Comparison-between-R-and-MATLAB-td18000568.html">again more recently. http://www.math.umaine.edu/~hiebeler/home.html">David Hiebeler (at the University of Maine) maintains an extensive http://www.math.umaine.edu/~hiebeler/comp/matlabR.html"><b>R/MATLAB comparison, and is the best reference on the subject. You can also review http://home.online.no/~pjacklam/r/doc/matlab_vs_r.html">this comparison of basic functions.

Here are some of the things that I've observed in the past, none of which should be deal-breakers.

  • Generally, MATLAB has a better programming environment (e.g. better documentation, better debuggers, better object browser) and is "easier" to use (you can use MATLAB without doing any programming if you want). Simulink allows you to visually program by connecting blocks in graphs. http://www.revolution-computing.com/">REvolution R is addressing some of these differences by providing a better IDE with improved debugging, but it's still a step behind.
  • MATLAB is a little faster with the normal configuration (http://mlg.eng.cam.ac.uk/dave/rmbenchmark.php">see this benchmark for an example), although there are things that can be done to improve R performance if that becomes an issue.
  • Since it's commercial, it also arguably has more "products" (in the sense of integrated add-ons) and support (but you pay for it). See the http://www.mathworks.com/products/product_listing/index.html">product list. For instance, it has things like http://www.mathworks.com/products/compiler/">the MATLAB compiler which creates executable MATLAB programs that can be deployed.
  • So far as packages/toolkits are concerned, MATLAB has much more support for the physical sciences while R is stronger for statistics, which is not to say that the other can't perform these tasks. And they can both be easily extended.

So, if ease-of-use isn't a primary concern (and there's no other business reason to avoid using an open-source tool), then I think that there's a real case to be made for using R. It has a very strong community around it (the R mailing lists are amazing), is rapidly developing (see CRAN), and it's free (which isn't a small issue!).

Edit: I would just add one further point to this: the book http://www.springer.com/statistics/computational/book/978-0-387-98184-0">"Functional Data Analysis with R and MATLAB" includes a chapter on the "Essential Comparisons of the Matlab and R Languages". This covers some important syntax differences (such as the interpretation of a dot, or the meaning of square brackets []). The book itself is well worth reading for anyone interested in functional programming (in either language).

Solution 2 - Matlab

R is an environment for statistical data analysis and graphics. MATLAB's origins are in numerical computation. The basic language implementations have many features in common if you use them for for data manipulation (e.g., matrix/vector operations).

R has statistical functionality hard to find elsewhere (>2000 Packages on CRAN), and lots of statisticians use it. On the other hand, MATLAB has lots of (expensive) toolboxes for engineering applications like

  • image processing/image acquisition,
  • filter design,
  • fuzzy logic/fuzzy control,
  • partial differential equations,
  • etc.

Solution 3 - Matlab

I have used both R and MATLAB to solve problems and construct models related to Environmental Engineering and there is a lot of overlap between the two systems. In my opinion, the advantages of MATLAB lie in specialized domain-specific applications. Some examples are:

  • Functions such as streamline that aid in fluid dynamics investigations.

  • Toolboxes such as the image processing toolset. I have not found a R package that provides an equivalent implementation of tools like the watershed algorithm.

In my opinion MATLAB provides far better interactive graphics capabilities. However, I think R produces better static print-quality graphics, depending on the application. MATLAB's symbolic math toolbox is also better integrated and more capable than R equivalents such as Ryacas or rSymPy. The existence of the MATLAB compiler also allows systems based on MATLAB code to be deployed independently of the MATLAB environment-- although it's availability will depend on how much money you have to throw around.

Another thing I should note is that the MATLAB debugger is one of the best I have worked with.

The principle advantage I see with R is the openness of the system and the ease with which it can be extended. This has resulted in an incredible diversity of packages on CRAN. I know Mathworks also maintains a repository of user-contributed toolboxes and I can't make a fair comparison as I have not used it that much.

The openness of R also extends to linking in compiled code. A while back I had a model written in Fortran and I was trying to decide between using R or MATLAB as a front-end to help prepare input and process results. I spent an hour reading about the MEX interface to compiled code. When I found that I would have to write and maintain a separate Fortran routine that did some intricate pointer juggling in order to manage the interface, I shelved MATLAB.

The R interface consists of calling .Fortran( [subroutine name], [argument list]) and is simply quicker and cleaner.

Solution 4 - Matlab

One big advantage of MATLAB over R is the quality of MATLAB documentation. R, being open source, suffers in this respect, a feature common to many open source projects.

R is, however, a very useful environment and language. It is widely used in the bioinformatics community and has many packages useful in this domain.

An alternative to R is Octave (http://www.gnu.org/software/octave/) which is very similar to MATLAB, it can run MATLAB scripts.

Solution 5 - Matlab

In my experience moving from MATLAB to Python is an easier transition - Python with numpy/scipy is closer to MATLAB in terms of style and features than R. There are also open source direct MATLAB clones Octave and Scilab.

There is certainly much that MATLAB can do that R can't - in my area MATLAB is used a lot for real time data aquisition - most hardware companies include MATLAB interfaces. While this may be possible with R I imagine it would be a lot more involved. Also Simulink provides a whole area of functionality which I think is missing from R. I'm sure there is more but I'm not so familiar with R.

Solution 6 - Matlab

Short answer: no, of course not. While any set of mathematical software packages will have their overlaps, they will always have biases towards certain problem domains. These biases figure strongly in whether or not you want to use one of these packages.

An example of what MATLAB can do that R cannot is interface to real-time hardware for signal processing/acquisition and control. A Simulink model in MATLAB can be configured both to run in simulation on your machine before compiling the code to execute on a real system taking measured data as input and calculating appropriate outputs (what was before a simulation of a control system is now a fully functioning one). With the appropriate hardware board in your machine, you can run real-time control systems through a PC.

R, by contrast, seems firmly set in the role of statistics, where I'm sure it out-performs what MATLAB can do. Similarly, Mathematica is better than MATLAB at symbolic maths; Python is better than MATLAB at general programming; gnuplot is better than all of them at actually creating graphs (er, I assume); and so on.

Solution 7 - Matlab

I agree with many of the answers given above. Since the answer is specific to the diffset of MATLAB and R capabilities, I will mention a very important one: MATLAB includes a JVM and has flawless and robust interoperability with Java. All of Java's vast universe of libraries is accessible to the MATLAB user. The MATLAB IDE can be almost be used as a poor man's Eclipse. In comparison, rJava is very immature, despite the very valuable effort of its creator (Roman Francois).

Solution 8 - Matlab

We can't because it's expected/required by our customers.

Solution 9 - Matlab

With the sqldf package, R is capable of not only statistics, but serious data mining as well - assuming there is enough RAM on your machine.

And with the RServe package R becomes a regular TCP/IP server; so you can call R out of java (or any other language if you have the api). There is also a package in R to call java out or R.

Solution 10 - Matlab

As a user of both MATLAB and R, I think they are very different applications. I myself have a background in computer science, etc. and I can't help thinking that R is by statisticians for statisticians whereas MATLAB is by programmers for programmers.

R makes it very easy to visualize and compute all sorts of statistical stuff but I wouldn't use it to implement anything signal processing related if it was up to me.

To sum up, if you want to do statistics, use R. If you want to program, use MATLAB or some programming language.

Solution 11 - Matlab

Support for interactive graphics is much better in matlab than in R. I hate matlab as a language, but I get jealous when I see how its users can explore data with mouse operations, while I'm busy repeating commands with new values for xlim etc. Matlab also handles multi-panel plots much better than any of the R methods for the task. Generally, R graphics has a 1960s feel. It's fine for publication, but not the best solution for interactive exploration of data.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFrankView Question on Stackoverflow
Solution 1 - MatlabShaneView Answer on Stackoverflow
Solution 2 - MatlabrcsView Answer on Stackoverflow
Solution 3 - MatlabSharpieView Answer on Stackoverflow
Solution 4 - MatlabJohnView Answer on Stackoverflow
Solution 5 - MatlabrobinceView Answer on Stackoverflow
Solution 6 - MatlabWill RobertsonView Answer on Stackoverflow
Solution 7 - MatlabgappyView Answer on Stackoverflow
Solution 8 - MatlabNzbuuView Answer on Stackoverflow
Solution 9 - MatlabAlexView Answer on Stackoverflow
Solution 10 - MatlablhahneView Answer on Stackoverflow
Solution 11 - MatlabdankView Answer on Stackoverflow