Department of Engineering

IT Services

Matlab

MATLAB is a high performance interactive software package for scientific and engineering computation. MATLAB integrates numerical analysis, matrix computation, signal processing and graphics in an easy-to-use environment where problems and solutions are expressed just as they are written mathematically. To start MATLAB on our system just type matlab in a terminal window or find the Matlab icon in the applications panel (use the appsicon button).

Introductions

We have various handouts online. Mathworks' own Getting Started with MATLAB is useful. Alternatives are CUED's Getting Started with Matlab (PDF version) and Matlab by Example. Getting to know Matlab is less technical. The Matlab Primer gives an out of date description of facilities. Using Matlab at CUED (PDF version) lists the added local features, and gives answers to many questions commonly asked at CUED. Mathworks' Using MATLAB gives more details on maths, graphics, object-oriented programming etc.

Our 2nd year Introduction to Octave can be used for Matlab.

A Matlab databook (PDF version) is in preparation, aimed at 3rd and 4th years.

See also Introduction to Matlab (MIT OpenCourseWare), especially the Assignments

Toolboxes

Toolboxes are libraries of extra routines.

  • The Symbolic Math Toolbox gives access to the full Maple library of routines to factorise, integrate, solve etc, symbolically. Type mhelp intro within matlab for details.
  • The Statistics Toolbox User's Guide includes a tutorial.
  • Also installed is the WaveLab toolbox for investigating Wavelets. Read the introductory handout for details. Type WavePath to get started and see a list of demos.

Typing ver inside Matlab lists the other toolboxes that we're licensed to use. If we don't have something you want, try

Getting help

Matlab has its own text-only help system (type help from the matlab prompt) and WWW-based documentation (see the online documentation or type doc). There are some video tutorials you can play (see the Demos sections, especially "Desktop Tools and Development Environment"). Use matlabdoc -a to list documentation files available in the alternative (PDF) format. "matlabdoc -a newfeat", for example, will display the 'New Features' document.

The Mathworks site has many resouces too -

Some short local articles are now online

Articles elsewhere include

Numerical Computing with MATLAB and Experiments with MATLAB by Cleve Moler are online textbooks.

If you have problems, you can try using matlab's debug facility (begin with dbstop). Alternatively, local users can

Some ancient manuals can be borrowed from the operators in the Engineering dept's DPO. Documentation from other universities is available

  • Some Control Tutorials from the University of Michigan may be useful. They include animations.
  • The University of New Hampshire has online tutorials

Simulink

SIMULINK is an extension of MATLAB that lets you model a system graphically. It adds to Matlab many features specific to dynamic systems while retaining all of MATLAB's general purpose functionality. See Simulink's documentation for details.

In January 2007 Mathworks identified bugs in R14SP3 Simulink(R) code generation products, which in rare instances generate incorrect code that is not easily detected. These bugs have been fixed in subsequent releases: R2006a, R2006b, or the upcoming R2007a release, so if you used R14SP3 to generate code, upgrade and regenerate.

Using Matlab with Fortran and C++

Matlab can also be used from C++ and fortran as a library of maths and graphics routines. Also C++ and fortran code can be called from within matlab. An Interface Guide is online. Current examples are in /usr/local/apps/matlab/matlabR2007a/extern/examples/ on our Linux servers. Local users using these files on the linux servers should note that some local configuring may be required - see Matlab: configuring mex page.

We have 1 license centrally maintained for Mathworks' compiler that converts MATLAB programs into stand-alone applications (though the royalty-free MATLAB Compiler Runtime (MCR) needs to be installed for the "stand-alone application" to work). Note that MATLAB's matrix-oriented operations are already highly optimized. As a result, the MATLAB Compiler is unlikely to significantly speed up functions that spend most of their time in MATLAB's built-in indexing, math, or graphics functions, or that are heavily vectorized.

Optimisation and long jobs

See the Running Long Programs documentation before running long jobs. Matlab scripts can often be speeded up considerably with little work - see the Faster Scripts document. The first 2 methods mentioned below have speeded up some CUED programs by a factor of 10 or so.

  • Use sparse matrices when you can. They may save you a great deal of space and time. See matlab's sparse command.
  • Use matrix operations instead of for loops - i.e. vectorise your code. See the Tricks page and Peter Acklam's MATLAB array manipulation tips and tricks.
  • Functions are faster than scripts - they get compiled internally the first time they are run.
  • If you know the maximum size that a matrix will be, create it that size initially, rather than letting it grow incrementally.
  • Use pack every so often to tidy up memory usage.

Parallelisation

The Matlab and parallel computing page has information. Newer versions of matlab exploit multi-core CPUs. On our linux servers the following graph shows the speed-up factors for a range of tasks

multithread

Note that some operations aren't speeded up, whereas others are over 3 times faster (the y axis running from 0 to 3.5). To exploit multi-processors more fully (or to use several machines in parallel) you need extra software. Here are some of the alternatives, not all of which are free.

See Mathworks' Enhancing Multicore System Performance Using Parallel Computing with MATLAB article.

New Facilities

Added facilities include

  • August 2014: The default version is Matlab R2014a
  • April 2014: Matlab R2014a installed. To run it, type matlabR2014a
  • August 2013: The default matlab is release R2013a.
  • July 2012: The default matlab is release R2012a.
  • September 2010: The default matlab is release R2010a.
  • September 2009: The default matlab is release R2009b.
  • November 2008: movietogif installed - converts movies to animated GIFs.
  • September 2008: The default matlab is release R2008a.
  • April 2008: matlabR2008a installed. Default is still the old matlab.
  • July 2007: Matlab R2007a installed on the Unix Teaching System.

Installing Matlab

Our site-license covers the following types of machine within the department - HP, Apple OSX, Compaq (DEC), SUN, Linux RedHat and machines running 32-bit/64-bit versions of Microsoft Windows which are connected to the department's network.

See the On-line Installation of Windows version of MATLAB page for Windows machines.

To activate your newly installed copy, see the Matlab Activation page.

Mail other installation requests to helpdesk.

In 2011 the department joined the university wide TAH (Total Headcount License) scheme for MATLAB. Members of staff, postgraduates and undergraduates can use the TAH license in standalone mode ie not connected to any network in their personal computers (laptops). For more information see the MATLAB Licensing Information page. If you have any queries email helpdesk

See our MATLAB Licensing Information and MATLAB - Frequently Asked Questions on Licensing at CUED for licensing details.

Old versions of Matlab are installed on CUED's central system under /usr/local/apps/matlab/

Purchasing Additional Licences for ToolBoxes

Mail helpdesk for license details.

Student Version (Buy Your Own Copy)

Students who need MATLAB on desktops/laptops (non-networked) can order it from Bookshops (this includes a book, Simulink and some Symbolic Toolbox functions). See Mathworks' Student Version page for details.

Any additional toolboxes (priced at US$59) can be purchased directly from the American web site using a credit card. These are only for bona fide students.

octave is free and may be useful to you. It's used in CUED undergraduate courses and is on the MDP Resource disc.