What langauge is MATLAB written in?

June 9th, 2012 | Categories: matlab | Tags:

As the resident MATLAB support guy (among other things) at The University of Manchester, I often get asked which language MATLAB is written in.  Many people seem to argue over whether or not it is Fortran or C with the prevailing wisdom being ‘It was originally written in Fortran for the free version 1 and then was re-written in C when it went commercial’.

Well, I am not sure about the history but looking at moden MATLAB, the question should be which languages, rather than which language!  The list I have so far is

  • C (many built in compiled mex functions are written in C)
  • C++ (MATLAB makes use of the Boost C++ libraries..thanks to M in the comments for this one)
  • CIL (Common Intermediate Langauge, used to be called MSIL, – The windows version of MATLAB uses this for various .NET stuff.  Thanks to ‘pmcs’ in the comments for this one)
  • NVidia CUDA (Routines in the GPU part of the parallel computing toolbox)
  • Bash shell script (On Linux, the startup ‘binary’ is a shell script)
  • Fortran (MATLAB uses the MKL and I’m fairly sure this is written in Fortran)
  • Java (Many of  the ticks in Yair Altman’s excellent book, Undocumented Secrets of MATLAB-Java Programming make use of the Java elements in MATLAB
  • MATLAB (many MATLAB functions are written in .m code)
  • Perl (Many mex-related scripts are written in Perl)
  • Windows batch files (I’ve seen some simple .bat files as part of the mex machinery)
  1. M
    June 9th, 2012 at 16:39
    Reply | Quote | #1

    It also appears to be using some C++ — notice the presence of several Boost DLLs in the binary directory, indicating the use of Boost C++ Libraries, http://www.boost.org/.

  2. June 9th, 2012 at 17:06
    Reply | Quote | #2

    Thanks for that…added to the list.

  3. pmcs
    June 9th, 2012 at 17:12
    Reply | Quote | #3

    In addition to C++, there’s also a fair bit of MSIL floating about in the Windows version. Presumably this is largely to help with .NET integration (which is, by the way, awesome, and even more useful than Matlab’s Java interop).

  4. June 9th, 2012 at 18:03
    Reply | Quote | #4

    Added, thanks :). I’ve not used the .NET interop stuff. Do you have a link to info showing its usefulness?

  5. StephenL
    June 9th, 2012 at 19:36
    Reply | Quote | #5

    I think one of MATLAB’s strengths is that so much of the language/features is built with the MATLAB language.

    There is a lot to learn and build from.

    Try doing that with R. If you don’t have experience in c or fortran, forget it.

    StephenL

  6. Mikhail
    June 9th, 2012 at 21:11
    Reply | Quote | #6

    MATLAB interpreter is definitively C++, when it crashes you can see the stack dump in the command window (red). Many people think first about Java because MATLAB UI is made with it, but it is just the presentation layer, not the core.

  7. June 10th, 2012 at 16:36
    Reply | Quote | #7

    As it is said in this document,

    http://software.intel.com/en-us/articles/using-intel-math-kernel-library-and-intel-integrated-performance-primitives-in-the-microsoft-net-framework/

    in the “Components – Implementation Details” section,

    “Intel® MKL implements CBLAS – the C interface to the BLAS […]”
    “LAPACK has only Fortran interfaces.” <– I assume it's written in Fortran then.

    Other parts are written in FORTRAN 77:

    http://software.intel.com/en-us/articles/using-cluster-mkl-pblasscalapack-fortran-routine-in-your-c-program/

    though I don't know which parts of MKL does MATLAB use, this was just a rapid Google search. So maybe we could say the kernel of MATLAB is written mainly in Fortran, or Fortran + C.

  8. Steve L
    June 11th, 2012 at 19:43
    Reply | Quote | #8

    For historical information, you can go back to the source. This Cleve’s Corner article is titled “The Origins of MATLAB” and in it Cleve discusses his original version of MATLAB (and the work that led up to it.)

    http://www.mathworks.com/company/newsletters/articles/the-origins-of-matlab.html