introduction to matlab n.
Skip this Video
Loading SlideShow in 5 Seconds..
Introduction to MATLAB PowerPoint Presentation
Download Presentation
Introduction to MATLAB

Loading in 2 Seconds...

play fullscreen
1 / 32

Introduction to MATLAB - PowerPoint PPT Presentation

  • Uploaded on

Introduction to MATLAB. 3 November 2009. Instructor: Andy Newman Office Hours: Stop by room 306 (main building) whenever Email: Website: Syllabus. Week 1 (11/03) Introduction to MATLAB GUI

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Introduction to MATLAB' - betty_james

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
introduction to matlab

Introduction to MATLAB

3 November 2009


Instructor: Andy Newman

  • Office Hours: Stop by room 306 (main building) whenever
  • Email:
  • Website:
  • Week 1 (11/03)
    • Introduction to MATLAB
      • GUI
      • Variables, operations, built in functions
      • Help
      • Script Files
  • Week 2 (11/10)
    • Programming
      • Syntax
      • Arrays: Numeric, cell, structure
      • Strings
      • Built in functions (i.e. find, mean, max, min, sum, etc)
      • File I/O (text, binary, netCDF, HDF)
      • Basic program organization
      • Debugging
  • Week 3 (11/17)
    • Graphics
      • Line, scatter, bar, surface, contour plots, etc
      • Figure properties (i.e. Axis labels, tick marks)
      • Colormaps
      • Saving your plots
      • Images in MATLAB
  • Week 4 (12/01)
    • Somewhat more advanced topics
      • Making functions
      • Vectorized code
      • 3-D plots
      • Data manipulation in MATLAB: regression, derivatives, others you want…
      • MATLAB Central File Exchange
  • Week 5 (12/08)
    • Toolboxes
      • Mapping
      • Signal processing
      • Statistics
    • Other topics you want to discuss
what is matlab
What is MATLAB?
  • MATLAB is a simple programming language with its own extensive library of mathematical and graphical subroutines
  • It integrates computation and graphics in one easy to use interface
  • MATLAB stands for MATrix LABoratory.
  • MATLAB is very extendable. There are many add-ons (toolboxes) for specific requirements
what is matlab1
What is MATLAB?
  • If MATLAB can process and visualize data, why ever use FORTRAN, C, or some other language?
  • MATLAB is an interpreted language
    • It is not a compiled language
    • Therefore identical code executes more slowly, sometimes MUCH more slowly in MATLAB
    • MATLAB has more memory overhead than equivalent FORTRAN or C programs
what is matlab2
What is MATLAB?
  • Main Features
    • Simple programming rules
    • Extended accuracy
    • Continuity among integer, real and complex values
    • Comprehensive mathematical library
    • Extensive graphics tools
    • Linkages with other languages
    • Transportability across environment
      • MATLAB scripts will work on PC, UNIX, Mac
starting matlab
Starting MATLAB
  • On UNIX: type matlab at command prompt
  • Click on the MATLAB icon if you are on a PC
  • Mac can probably do both…
  • Issues on startup
    • MATLAB needs a connection to the license server
    • Check internet connection
    • Too many users can use all available licenses
      • Try again later
starting matlab1
Starting MATLAB
  • Once MATLAB is running the GUI (Graphical User Interface) will appear
    • Default Window apperance
starting matlab2
Starting MATLAB
  • Command Window
    • Main window in MATLAB
    • Commands entered here
starting matlab3
Starting MATLAB
  • MATLAB displays >> prompt when ready for a command
    • Will have no >> prompt when processing commands
    • Newer versions also say “Ready” or “Busy” in lower left corner of GUI
    • Can use arrow keys to work through command history and modify commands
      • Essentially the same as UNIX command prompt
matlab gui
  • Current Folder Window
    • Displays contents of the current working directory
    • MATLAB Search Path
      • Path that MATLAB uses to search for script and function files
      • Default path contains all built in MATLAB functions
      • Can modify path through MATLAB function or going under File>Set Path
      • MATLAB will ask to modify path if running a program from a folder not in path
matlab gui1
  • Workspace Window
    • Shows all currently defined variables
    • Array dimensions
    • Min, max values
    • Good debugging tool
  • Command History
    • Shows all past commands
    • Can copy and past commands into command window
    • Double click will execute command
matlab gui2
  • Other windows include editor window, figure window, variable editor, help, etc
  • Will discuss editor and figure window in upcoming weeks, get to help window in a little bit
matlab gui3
  • Desktop Menus
  • File Menu
    • New
      • Create new MATLAB program file (m-file)
    • Open existing m-file
    • Import data
    • Set Path
    • Open recent m-files
matlab gui4
  • Edit Menu
    • Copy, cut, paste
    • Find and replace phrases
    • Clear command history, workspace
  • Desktop Menu
    • Change appearance of desktop
      • Select windows to display
interactive commands
Interactive Commands
  • Enter commands at >> prompt
  • Variable ‘x’ automatically allocated
    • MATLAB does not require declaration of variables
    • Nice, but can get you in trouble so be careful
interactive commands1
Interactive Commands
  • MATLAB is case sensitive
    • Variable ‘ans’ will take value of result of command if no equal sign specified
      • Holds most recent result only
    • Semicolon at end of line will suppress output, it is not required like in C
      • Useful in script files and debugging
interactive commands2
Interactive Commands
  • Format of output
    • Defaults to 4 decimal places
    • Can change using format statement
    • format long changes output to 15 decimal places
  • Scalar arithmetic operations

Operation MATLAB form

    • Exponentiation: ^ aba^b
    • Multiplication: * ab a*b
    • Right Division: / a / b = a/b a/b
    • Left Division: \ a \ b = b/a a\b
    • Addition: + a + b a+b
    • Subtraction: - a – b a-b
  • MATLAB will ignore white space between variables and operators
order of operations
Order of Operations
  • Parentheses
  • Exponentiation
  • Multiplication and division have equal precedence
  • Addition and subtraction have equal precedence
  • Evaluation occurs from left to right
  • When in doubt, use parentheses
    • MATLAB will help match parentheses for you
  • MATLAB is case sensitive
    • X is not equal to x
  • Variable names must start with a letter
    • You’ll get an error if this doesn’t happen
    • After that, can be any combination of letters, numbers and underscores
      • No special characters though
  • Variable types
    • Numeric
    • Logical
    • Character and string (discussed next week)
    • Cell and Structure (discussed next week)
    • Function handle (discussed in week 3)
  • Don’t name your variables the same as functions
    • min, max, sqrt, cos, sin, tan, mean, median, etc
    • Funny things happen when you do this
  • MATLAB reserved words don’t work either
    • i, j, eps, nargin, end, pi, date, etc
    • i, j are reserved as complex numbers initially
      • Will work as counters in my experience so they can be redefined as real numbers
matlab help
  • Ways to get help in MATLAB
    • help function name
    • Provides basic text output
  • Type helpwin on command line
  • Look under the help menu on the desktop
matlab help1
  • Product help window
    • Help>product help
matlab help2
  • Can browse or search product help for a specific function or topic
  • MATLAB help has introductory help material, basic overviews of how to use functions, plot, program in MATLAB, example code, etc
  • lookforkeyword command will also find functions that have the keyword in them
  • doc function_name brings up the full documentation for the function
  • Books
    • Two that seem to be good:
      • A Concise Introduction to MATLAB by William J. Palm III. 2008, McGraw-Hill, 418 pp.
      • Essential MATLAB for Engineers and Scientists (Fourth Edition) by Brian Hahn and Dan Valentine. 2010, Academic Press, 480 pp.
  • Online tutorials and examples are everywhere
  • Note that older books and tutorials may have options that are no longer available and functions that no longer work
    • Figures are the prime example
next week
Next Week
  • Arrays
  • Strings
  • File I/O
  • Program layout and debugging