What can MATLAB do that R cannot do? [closed]
Asked Answered
B

11

136

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?

Bulter answered 15/11, 2009 at 16:59 Comment(15)
by the way, there's another open source alternative: Octave is mostly Matlab compatibleInnutrition
I'd like to know what R can do that Python cannot do? (not a flame - really would like to know)Sample
@thrope: it just so happens that there's already a question for that: #1177519Blowtube
Technically, anything that can be done in one language can be done in any language (from a "what can it compute" point of view). It's just a matter of ease-of-use and ease-of-learningPainty
There's also FreeMat, and it's even more Matlab compatible. The big bonus of using Octave or FreeMat is that you can reuse your existing scripts.Titus
@Adria, @Innutrition There's also Scilab.Cabot
@BlueRaja - Danny Pflughoeft: If you'd thrown in the phrase Turing-Complete, I would have up-ticked you... ;-)Property
+1: Matlab can eat up my software budget. R has not managed to do this, yet.Kenay
To correct some other statements: it is not correct that one can reuse all Matlab code in Octave or FreeMat. There are some classes of functions that are not well implemented at all in the other versions. I have large blocks of code that I have found it better to implement anew in environments that have approximately similar functionality for just these classes of functions. Of the functionality that Matlab has that Octave does not, I have found surrogates in R, Python, and, to some extent, Java and C. Reimplementing libraries is harder than basic code. Pay attention to libraries...Kenay
What are your performance requirements (disk, memory, network, filesizes)? Are you touching a database? Are you operating totally offline or ar there any response-time or rate requirements? Do you care about scalability? Crash recovery? etc etcWein
The closing of this question is not justified. This question is not about polling, it's about what exactly you can do in Matlab but not in R. Such things can easily be enumerated and supported by references.Bulter
Too bad this question was closed. This is one of the best technical discussions I have ever seen on StackOverflow.Receive
This is the type of question that should have been closed before it garned responses. But closing it afterwards is inappropriate, so at this point it needs to be reopened out of respect for the effort of so many contributors.Sihun
Why so many deletevotes? I think a historical lock is in orderSullivan
R is the wiser choice, budget-wise, and reasonably fast. Octave may be almost the same as MATLAB (some minor syntax differences), but takes AGES for computation compared to MATLAB and is not suited for large data sets. Octave takes like 20 times as long as MATLAB from my experience.Euripus
B
128

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 Spencer Graves said previously, it also depends on which "church you happen to frequent". It's best if you look at the MATLAB toolkit vs. CRAN for a specific task before you decide.

A similar question asked on R-Help a few years ago and again more recently. David Hiebeler (at the University of Maine) maintains an extensive R/MATLAB comparison, and is the best reference on the subject. You can also review 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. 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 (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 product list. For instance, it has things like 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 "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).

Blowtube answered 15/11, 2009 at 16:59 Comment(8)
There's a nice matlab/R reference that shows how to perform equivalent tasks in each here: math.umaine.edu/~hiebeler/comp/matlabR.htmlGunflint
"[MATLAB] also arguably has more products and support". I disagree with this. CRAN and Bioconductor (for R) are much more comprehensive than MATLAB + the toolboxes + the File Exchange. Also, the R-Help mailing list is usually as effective as paid support, in my experience. I agree that the MATLAB compiler is a great feature that isn't replicated in R.Protege
Thanks Richie. I tried to clarify on that point a little further. And while I love the R mailing lists, I don't think that it's quite equivalent to calling a private company and requesting a critical bug fix on a minor package (where you're paying for support). Some of the less used R packages aren't as well maintained (although in some cases they don't even exist in Matlab).Blowtube
A lot of times R functions are better documented than those in Matlab. I find that the quality of Matlab documentation varies a lot from function to function and between (commercial) toolboxes. I agree that Matlab IDE is somewhat more beginner friendly, but it is not better than e.g. ESS for R if you use it on a daily bases.Dandelion
RStudio is a nice new R IDELuciolucita
Can R do Digital Signal Processing?Lactone
Looks like Revolution R costs $1000 per license.Mullen
Too bad this question was closed. This is one of the best technical discussions I have ever seen on StackOverflow.Receive
C
32

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.
Collete answered 15/11, 2009 at 18:7 Comment(3)
R has a large package repository called CRAN that provides a wealth of additional features (though I agree with your general point). Ex: a PDE solver: cran.r-project.org/web/packages/deSolve/index.htmlGunflint
MATLAB also has something analogous to CRAN: a sizable File Exchange (mathworks.com/matlabcentral/fileexchange) with over 10,000 user-submitted functions and toolboxes that are freely available.Abraxas
There is also a sizeable, free code base for MATLAB outside of MATLAB Central's File Exchange.Stockstill
H
26

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.

Hitt answered 16/11, 2009 at 3:31 Comment(1)
I should also mention that R gets a big plus in my book for the Sweave system for enabling reproducible research. Allowing anyone to re-run and analyze the computations behind a paper or report using a freely available tool is extremely important in my opinion.Hitt
L
22

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.

Lowrey answered 19/11, 2010 at 9:59 Comment(1)
All R submitted packages are tested for documentation and examples.Chili
S
21

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.

Sample answered 15/11, 2009 at 18:9 Comment(0)
S
11

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.

Stomodaeum answered 16/11, 2009 at 4:52 Comment(1)
R is actually known to be very good for creating graphs. They look very good too. Actually, the very first reason for me to look into R was I was jealous of some of the nice graphs that my colleagues had made, using R. So I switched from gnuplot and have never looked back.Bulter
D
11

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).

Dekameter answered 24/7, 2010 at 12:46 Comment(0)
V
9

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

Vasya answered 16/11, 2009 at 12:37 Comment(5)
This is a completely valid answer. It's important to realize that there are many industries that simply will not accept an open source solution. There are questionable compliance requirements that take R of the plate.Ettieettinger
@BrandonBertelsen: specifically, what?Wein
@Wein that statement is no longer as true as it was in 2010. Use of R has proliferated.Ettieettinger
Ok, but can you tell us as of 2010 what compliance requirements took R off the plate (and which are still an issue)?Wein
Our customers generally also use MATLAB and we're often required to exchange code and models with them. You generally find that the only industries that use R are mostly concerned with data sets and statistics.Vasya
E
5

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.

Eroto answered 10/5, 2011 at 18:46 Comment(1)
It's true, but the question is "What can MATLAB do that R cannot do?" not "What can R do that MATLAB cannot do?".Subrogation
C
4

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.

Corkscrew answered 15/11, 2009 at 19:42 Comment(12)
Come one, R is a programming language.Bulter
"Matlab is by programmers for programmers". MATLAB was originally written specifically to do linear algebra; it wasn't a general purpose programming language. Many of the general purpose language features have been tacked on afterwards. (It's only had a workable object oriented system for a year.)Protege
"Matlab is by programmers for programmers": Are you serious? The only thing that actually bugs me with MATLAB is that whoever invented the language was not a programmer, given the extremle awkwardness of the language in some situations.Logue
R was created by statisticians, Matlab was created by engineers. Both are fully capable programming languages.Hitt
@Sharpie: what on earth are you talking about? R does not pass dataframes by reference! As a result, unless you (mostly) avoid functions, you hit a scalability limit by having multiple copies of temporaries (garbage-collect later). So if your code was deeply recursive and you're on a 4Gb box, would you care to speculate what is the largest dataframe it could handle before dying? Do you think crashing in production code is acceptable? Is a language which hamstrings recursion 'fully capable'?Wein
R does arg-passing as pass-by-promiseWein
@Wein By "fully capable" I was calling out the answerer's implication that R was somehow not a programming language. R is turing-complete and therefore fully capable of being used a a programming language. As for the rest---I think you and I live in entirely different fields of use. R is vastly better than Excel which makes it more than enough for day to day munging of engineering data.Hitt
@sharpie: the question was not about data manipulation tools or spreadsheets, it was about scientific programming languages. Excel is not even a scientific programming language. If we assess R as a scientific programming language (which is what this question asked), it scores woefully on its approach to function call arg passing (hence you can't do recursion, which rules out huge families of algorithms), memory management, manual garbage collection. Arguing that Turing-completeness implies goodness or even adequacy is not a winner. Consider also the S3 vs S4 package mess.Wein
@sharpie: I ask you again: Do you think crashing in production code is acceptable? Are you honestly suggesting we should excuse that if a language is Turing-complete?Wein
@Wein The last time I swapped production Matlab code for R code was at the National Weather Service in 2008 and the system has been running without fault since. In-core processing of multi-gigabyte datasets using recursive algorithms is by no means a task representative of scientific computing as a whole and is therefore a poor choice of benchmark for making general statements about the suitability of a programming language.Hitt
@sharpie: nonsense. Noone said it was a 'benchmark'. I did point out proper support for recursion is one of the hallmark differences between (say) a data manipulation language which borrows bits from programming languages (as R is), vs a full programming language (as Python is). If you're saying 'scientific programming languages don't need recursion (not even under the hood)', that is true in some problem domains, and not true in others, so overall not really true. Let's leave it at that.Wein
IMO, any person relying on a lot of recursion is more a theoretical computer scientist than a programmer.Torp
S
2

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.

Sommer answered 23/1, 2012 at 12:17 Comment(2)
As a heavy user of both systems' interactive plotting tools, I will agree at the limits (i.e. as in I push both hard), but you're likely missing out on some very useful interactive graphing tools in R. Check out the following packages: iplots, Acinonyx, Rstudio's manipulate, and more. For fun, check out this example.Kenay
"R graphics has a 1960s feel" - that may have been true years ago. These days, with ggplot2 which is rapidly gaining popularity, R charts have a modern and beautiful look. See for example: r-bloggers.com/?s=ggplotTyre

© 2022 - 2024 — McMap. All rights reserved.