CHAPTER 1

Introduction to MATLAB





1.1 The MATLAB System


MATLAB is a high-level technical computing language and interactive environment for algorithm development, data visualization, data analysis, and numeric computation. The MATLAB system consists of the following parts:

  • Desktop Tools and Development Environment: This part of MATLAB is the set of tools and facilities that help you use and become more productive with MATLAB functions and files. Many of these tools are graphical user interfaces. It includes: the MATLAB desktop and Command Window, an editor and debugger, a code analyzer, and browsers for viewing help, the workspace, and folders.

  • Computing Language: The MATLAB language is a high-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features. It allows both "programming in the small" to rapidly create small programs and "programming in the large" to create complex application programs that will execute multiple times.

  • Mathematical Function Library: This library is a vast collection of algorithms that compute mathematical functions (ranging from sum, sine, cosine, or complex arithmetic to Bessel functions) or perform sophisticated operations (like matrix inversion, evaluation of matrix eigenvalues, or fast Fourier transforms).

  • Graphics: MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. It includes high-level functions for two-dimensional and three-dimensional data visualization, image processing, animation, and presentation graphics. It also includes low-level functions that allow you to fully customize the appearance of graphics as well as to build complete graphical user interfaces on your MATLAB applications.

  • External Interfaces: The external interfaces library allows you to write C/C++ and Fortran programs that interact with MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), for calling MATLAB as a computational engine, and for reading and writing MAT-files.

  • A description of most of the commands and techniques for programming can be found in the Getting Started with MATLAB Users' Guide. These notes cover only a small number of these commands so if you wish to expand your use of MATLAB you should obtain or have access to one of the User's Guides.




    1.2 Online Resources

    MathWorks, MATLAB's vendor, maintains a web site with many links to online resources that will introduce you to the use of MATLAB. These resources include:




    1.3 Starting and Quitting MATLAB

    On Microsoft Windows machines, start the MATLAB program by double-clicking the MATLAB shortcut on your Windows desktop.
    On Apple Macintosh machines, start MATLAB by double-clicking the MATLAB icon in the Applications folder.
    On UNIX platforms, start MATLAB by typing matlab at the operating system prompt.

    When you start MATLAB, the desktop appears, containing tools (graphical user interfaces) for managing files, variables, and applications associated with MATLAB. The following illustration shows the default desktop with the Command Window panel on the right, the Workspace in the top left panel and the Command History in the bottom left panel.

    You will type your commands in the Command Window. The output generated by a command (e.g. the result of a mathematical opearion) will also appear in the Command Window. The Workspace window will display a list with the names and values of all the variables you have defined, and the Command History window will display a complete record of all the commands you have typed.

    desktop1

    Let us assign the value of 3 to a variable x by typing x=3 after the prompt >>. MATLAB echoes the variable assignment in the Command Window and updates the Workspace and Command History windows as shown in the following illustration.

    desktop2

    Let us now assign the value of 4 to another variable y and issue the command z=x+y to compute the sum of x and y. Note that the use of a colon ; at the end of the command y=4 has suppressed the output (echo) of the assignment of variable y. The following illustration shows the result of the operation displayed in the Command Window and the updated Workspace and Command History windows.

    desktop3

    You can customize the arrangement of tools and documents to suit your needs. In the following illustration, the current directory and its contents are displayed in the top left window instead of the Workspace.

    desktop2

     

    To end your MATLAB session, select the File > Exit MATLAB menu option, or type quit in the Command Window.




    1.4 Scalar Arithmetic Operators

     
    Operation
    MATLAB Form
    +
    Addition
    a+b
    -
    Subtraction
    a-b
    *
    Multiplication
    a*b
    /
    Right Division
    a/b
    \
    Left Division
    a\b
    ^
    Exponentiation
    a^b

    MATLAB executes scalar operations with the following order of precedence:

    Precedence

    Operation

    First
    Parentheses: Evaluated starting with the innermost pair
    Second
    Exponentiation: Evaluated from left to right
    Third
    Multiplication and division with equal precedence:
    Evaluated from left to right
    Fourth
    Addition and subtraction with equal precedence:
    Evaluated from left to right


    PRACTICE: Precedence

    Perform the following operations with MATLAB:

    • 8+3*5
    • (8+3)*5
    • 4^2-12-8/4*2
    • 3*4^2+5
    • (3*4)^2+5
    • 27^(1/3)+32^0.2
    • 27^1/3+32^0.2

     




    1.5 Getting Help


    There are several ways to get help for MATLAB commands or functions.

    1. Type help fname in the Command Window. A description of the the function (or command) fname is diplayed in the Command Window as shown in the following illustration.

      help1

    2. Type lookfor topic in the Command Window. A list of all functions whose description includes the specified keyword topic is displayed in the Command Window as shown in the following illustration.

      help2

    3. Type doc fname. The Help browser opens to the reference page for the specified function or command fname, providing a description, additional remarks and examples.

      help3


    In addition to giving you a way to find out about functions that are not described in these notes or in the User's Guide, the help command will frequently show you new ways to use functions. Both the developers of MATLAB and the authors of functions for your courses frequently expand the scope of functions to make them more useful.


    PRACTICE: Help

    Get help for the following MATLAB commands:

    • clc
    • who
    • whois
    • clear
    • exist
    • quit




    Continue on to Chapter 2
    Return to Table of Contents