How to Get Started with MATLAB at UMBC

Purpose of this Document

This document explains how to get started with MATLAB on computer systems at UMBC. It will not tell you how to use MATLAB, but rather, where to find the appropriate information to learn more.

If you are interested in how to use MATLAB, come to free software workshops offered by CIRC. They are held during Fall and Spring semesters on Wednesdays during Free Hour (12noon-01pm) in room ENGR 122, an instructional computer lab in the Engineering Building at UMBC. The workshops on MATLAB form a sequence that covers topics from a basic introduction to efficient simulations.

For a more thorough introduction with guided homework projects, consider the official 2-credit class MATH 426 Introduction to Math Software Packages: MATLAB that the Department of Mathematics and Statistics offers in Summer and Winter semesters.

What is MATLAB?

MATLAB’s name originates from Matrix Laboratory, since it was originally written as a teaching tool to support an introductory linear algebra class (like MATH 221 at UMBC). Since that first version, it has been extended and upgraded to be one of the most versatile and popular packages for numerical computations and graphing. It is widely used in industrial companies, government agencies, and educational institutions for rapid prototyping and teaching. Its main popularity roots in its intuitive interactive interface combined with reliable numerical algorithms and professional graphics capabilities.

For the official description of MATLAB, check out http://www.mathworks.com, the webpage of the MathWorks, Inc., maker of MATLAB.

Where Can I Use MATLAB at UMBC?

UMBC maintains a campus licenses for MATLAB and many of its toolboxes. The most efficient way to run MATLAB is to use a lab PC and run it locally. You may also run it remotely on several of the gl systems.

DoIT Computer Labs – Current Version: R2018b – As of  9-27-2018

Starting MATLAB in Windows

Under Windows 7 or 8, click on the Windows Start Orb to open the Start Menu, type “matlab” to search for the program, then click on the version you want to run. MATLAB might remember whether you had other windows open at the end of your previous session, so the Help browser (which might even open with the page you last visited) and other windows may open again.

In the UMBC computer labs, MATLAB starts up with your current working directory set to your local home folder. This directory is visible in the “Current Folder Toolbar” above the other desktop windows and below the “Toolstrip”.

As an example of how to create a directory structure for your current project, here are instructions that a student in Math 426 can use to to organize her files for that course. First, create a folder for this class by entering “mkdir Math426” on the MATLAB command line (the window with the >> prompt), and then change into it by entering “cd Math426“. Next, create a directory for each homework by entering “mkdir Homework1” and change to it by entering “cd Homework1“. Check what the Current Folder Toolbar says or enter “pwd” (print working directory) at the MATLAB command line.

Starting MATLAB in Linux

Under Linux, you need to get a command window (shell) first. Then, enter “matlab” at the command window prompt (and press return). To get more information on command line options, enter “matlab -h” at the Linux command prompt, which gives information about possible command line arguments, but does not start MATLAB. MATLAB might remember whether you had other windows open at the end of your previous session, so the Help browser and other windows may open again.

Under Linux, it makes more sense to change directory first at the Linux command line and before starting MATLAB, using the Linux commands “mkdir” and “cd” (and “pwd” and “ls” to inquire). Then, start MATLAB in your desired directory which will make all files associated with your project accessible.

 

Running MATLAB Remotely from Windows

See that section under the General Productivity portion of the High Performance Computing Facility (HPCF) webpage. There, you will find instructions which include installing PuTTY (for the remote SSH connection) and Xming (for remote graphics). If you do not wish to use graphics, perhaps because the connection is slow, you may want to start MATLAB (i) without its desktop and (ii) without any graphics (including the splash screen); this can be accomplished by using “matlab -nodesktop -nodisplay“. To get more information on command line options, enter “matlab -h“.

High Performance Computing Facility (HPCF) – Current Version: R2016b (9.1.0.441655) 64-bit (glnxa64) – As of 9-27-2018

The maya cluster is accessible to individuals with an account through HPCF. Connecting to maya is done remotely.

Running MATLAB on maya

See How to run MATLAB programs on maya for running MATLAB interactively on maya after an SSH session has been intiated.

Running MATLAB programs on maya in batch mode

A detailed description along with examples of how to run MATLAB on maya is provided on the HPCF webpage. The cluster maya is meant for batch processing, so this is the preferred mode of running MATLAB for production runs.

How to Get Help from MATLAB

There are several ways to get help from MATLAB. MATLAB’s internal documentation, described in the next section, is very useful. Additionally, searching the internet, e.g., via google.com, has recently increasingly proven to be a very useful way to debug problems. While searching the internet, you will discover several online forums for posting and answering questions about MATLAB.

Help Available Inside the Command Window

The command window is the one with MATLAB’s “>>>” prompt. Two MATLAB commands can give you help inside this window (without starting any other windows, etc.), which might be important if you use MATLAB remotely. Also, the help accessible in this way would work for functions and scripts written by you.

The command “help functionname” displays the help on the function called “functionname“. This syntax works for any function that is be in the current directory or on the search path. Use “which functionname” to find out exactly which function on the search path is being called. The “help” command works by displaying the comments at the beginning of the m-file with name functionname.m up to the first blank line or the first line of code.

If you do not know the name of the function, you can search for it using the “lookfor keyword” command, which searches for “keyword” in the first line following the function declaration (called the H1 line) of all m-files on the search path. Use “help lookfor” for an explanation of how to expand this search to the entire first comment block of each m-file.

Full Graphical Help

If you use MATLAB on your local machine, the Help browser is available to access the complete documentation in many different ways, including by topic from the table-of-contents of the manuals, by name of function, or by (full-text) keyword search. There are many different ways to start this Help browser, including several under the Help menu of the desktop or by clicking the question mark “?” near the top of the desktop. Or from the prompt “>>” in the command window enter “helpbrowser”. You could also say helpdesk, helpwin, or doc, which might differ from each other by the page displayed in the Help browser upon opening. Try out what seems most useful to you. Note that MATLAB might remember which page you looked at last in your previous session, so it is useless to predict exactly what will happen under various circumstances.

Besides starting the Help browser and then using its features to find what you want, you can directly open the Help broswer for a particular function functionname by entering “doc functionname“. It is sometimes necessary to issue this command twice to get the desired effect, though. If the Help browser is not open yet, it is started up, or if it is already open, the page displayed is changed. The help content via entering “doc functionname” is similar, and in some cases identical, to that obtained via entering “help functionname“, but the former command often has more information and additional examples; and, especially for graphics commands, you will find full examples which would not be available by using “help” in the command window alone. However, sometimes the more compact information inside the command window has its advantages. Try comparing the information available from “help plot” with “doc plot“.

How to Get Started with MATLAB

The best way to get started is to read MATLAB’s internal documentation via the Help browser. From within MATLAB, you can open the Help browser by typing “doc” at the prompt of the command window.

Help opens with tabs for Installation and Release Notes, and with available help for the main MATLAB package, as well as all of the installed Toolboxes.

An excellent way to learn about MATLAB’s features and how to use them is to study the “Getting Started with MATLAB” guide. To access the guide, click on the link and then click on the first tab under called “Getting Started”.

The “Getting Started with MATLAB” guide explains the philosophy of MATLAB (including the features of the desktop environment) and walk you through the most basic commands. You should try out commands in the command window while reading the Getting Started guide. The guide has several tutorials including the “2-D and 3-D Plots” tutorial which explains the use of graphics commands. The “Programming and Scripts” tutorial explains how write Matlab scripts, including the use of loops and conditional statements.

In addition to this help inside of MATLAB, MathWorks also makes the documentation available online. Try an internet search like “matlab handle graphics”, and one of the first results will be MathWorks’ online documentation.