Computation for the Sciences: Lab 1 :: Introduction to MATLAB

MATLAB desktop and interactive environment

Getting started:

On a Macintosh, start MATLAB by clicking on this icon:
How to find MATLAB on a Wellesley public computer:
  • Macintosh:
    • From the Go menu at the top of your screen, select Applications
    • This opens the Applications window.
    • From within this folder, select MATLAB 7.0.4
    • Now you can click on the MATLAB icon shown above
  • PC:
    • Click here for how to find MATLAB on a PC.


Important parts of your MATLAB screen:


  • Command Window
    (circled in red)
    Where you type your commands
  • Command History
    (circled in green)
    Keeps a record of your commands
  • Current Directory Window
    (circled in blue)
    Allows access to current directory
  • Workspace
    (circled in magenta but window not shown)
    Variables (more on this later) are tracked here


Download the lab1 folder from the download directory

Download a copy of the lab1_programs folder from the download directory onto your desktop.
Rename the folder to be yours, e.g. stella_lab1_programs.

:: Helpful hints ::
  • Resize your MATLAB window via the lower right corner
  • Restore your MATLAB window
    If your MATLAB windows somehow change their appearance, you can always restore your setup by selecting Desktop -> Desktop Layout -> Default and this will recover your old MATLAB window appearance (see below)

  • Reduce extra blank lines
    By typing format compact into your Command Window

  • Use the arrow keys
    Use the up-arrow key to 'yank' back previously typed commands in the Command Window. The left and right-arrow keys can help you edit within a line.
  • Recycle content from Command History window
    You can highlight and select content from the Command History window into your Command window (faster and more accurate than re-typing!)
  • Clear the command window
    clc clears the command window
  • Comments in your code
    • % indicates a comment. MATLAB ignores everything after the % sign. For example:
      % Computation for the Sciences: Lab 1
      is a comment. Note that comments in the MATLAB editor appear green.
    • Commenting out chunks of code while debugging

      Select code with your mouse, then choose Text -> Comment from the menus (and you can uncomment code as well).

Let's work with MATLAB now:


Exercises

  1. MATLAB Practice
  2. Variables in MATLAB
  3. Exploring MATLAB's help

Uploading your saved work

We'll use Fetch again, but this time you will access your own personal account and password. This time, login to Fetch using your username (the one you used when filling out the account request form, probably the same username as your firstclass username).
  • Browse through your account, finding the drop/assign# folders
  • Learn how to delete a file from your account
  • Upload your stella_lab1_programs folder into your personal account
  • When done uploading, be sure to delete your stella_lab1_programs folder from the desktop (by putting it in the trash can) and then empty the trash (Finder--> Empty Trash).
  • Exit out of MATLAB when done