CPET 190 - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

CPET 190

Description:

ver - Current MATLAB and toolbox versions. version - Current ... FORMAT LONG E Floating point format with 15 digits. format long x. x = 0.33333333333333 ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 33
Provided by: Paul6
Category:
Tags: cpet | longe

less

Transcript and Presenter's Notes

Title: CPET 190


1
CPET 190
  • Lecture 3
  • Problem Solving with MATLAB
  • http//www.etcs.ipfw.edu/lin

2
Lecture 3 MATLAB Development Environment
  • 3-1 Desktop Tools
  • Starting and Quitting MATLAB
  • Command Window
  • Running Functions
  • Entering Variables
  • Controlling Input/Output
  • Searching Items
  • Running Programs
  • Preferences for the Command Window

3
Lecture 3 MATLAB Development Environment
(continue)
  • 3-1 Desktop Tools (continue)
  • Command History
  • The MATLAB Workspace
  • Help Browser
  • Workspace Browser
  • Current Directory Browser
  • Edit/Debug

4
Lecture 3 MATLAB Development Environment
(continue)
  • 3-2 Useful Commands
  • The MATLAB Search Path
  • Number Display Formats
  • Session Log
  • MATLAB Managing Commands and Functions
  • demo - Run demos
  • help - Online help
  • ver - Current MATLAB and toolbox versions
  • version - Current MATLAB version number
  • path - MATLAB Search path
  • diary - Save typed commands on a named file
  • Summary

5
Starting and Quitting MATLAB
  • Starting MATLAB
  • From command window start -gt Run -gt MATLAB
  • Start -gt All Programs -gt MATLAB

6
Starting and Quitting MATLAB
  • Quitting MATLAB
  • At the MATLAB command window
  • gtgt quit
  • gtgt exit
  • Close MATLAB Window

7
Desktop Tools
  • Started MATLAB and see the three sub-windows
  • Command Window
  • Current Directory
  • Command History
  • At the command
  • window, we enter
  • gtgthelp help

8
Command Window
  • Running Functions
  • Entering Variables
  • Controlling Input/Output
  • Searching Items
  • Running Programs
  • Setting Preferences for the Command Window

9
Running Commands
  • An Example
  • gtgt magic(3)
  • ans
  • 8 1 6
  • 3 5 7
  • 4 9 2

gtgt help magic MAGIC Magic square. MAGIC(N)
is an N-by-N matrix constructed from the
integers 1 through N2 with equal row,
column, and diagonal sums. Produces valid
magic squares for all N gt 0 except N 2.
10
Entering Variables
  • gtgt x 10
  • x 10
  • gtgt y 10
  • y 10
  • gtgt x y
  • ans 100
  • gtgt x / y
  • ans 1
  • gtgt x y
  • ans 20
  • gtgt x - y
  • ans 0
  • gtgt

11
Controlling Input/Output
  • Format Function control the display formats for
    numeric values
  • Examples
  • gtgt x 1/3
  • x 0.3333
  • gtgt y 1.2345e-7
  • y 1.2345e-7
  • gtgt format short e
  • gtgt x
  • x 3.3333e-001
  • gtgt y
  • y 1.2345e-007

Hit Enter key
MATLAB Displays
Hit Enter key
Hit Enter key
Enter x
MATLAB Displays
Enter y
MATLAB Echoes
12
Controlling Input/Output (continue)
  • Format Function
  • gtgt help format
  • FORMAT Set output format.
  • All computations in MATLAB are done in double
    precision.
  • FORMAT may be used to switch between different
    output
  • display formats as follows
  • FORMAT Default. Same as SHORT.
  • FORMAT SHORT Scaled fixed point format
    with 5 digits.
  • FORMAT LONG Scaled fixed point format
    with 15 digits.
  • FORMAT SHORT E Floating point format with 5
    digits.
  • FORMAT LONG E Floating point format with
    15 digits.

gtgt format long gtgt x x 0.33333333333333 gtgt
y y 1.234500000000000e-007
13
Controlling Input/Output (continue)
gtgt format long g gtgt x x 0.333333333333333 gt
gt y y 1.2345e-007 gtgt format
bank gtgt x x 0.33 gtgt y y 0.00 gtgt format
rat gtgt x x 1/3 gtgt y y 1/8100446
  • Format Function
  • gtgt help format
  • FORMAT SHORT G Best of fixed or floating point
    format with 5 digits.
  • FORMAT LONG G Best of fixed or floating
    point format with 15 digits.
  • FORMAT HEX Hexadecimal format.
  • FORMAT The symbols , - and blank
    are printed for positive, negative and zero
    elements. Imaginary parts are ignored.
  • FORMAT BANK Fixed format for dollars and
    cents.
  • FORMAT RAT Approximation by ratio of
    small integers.

14
Controlling Input/Output (continue)
  • File -gt Preferences
  • Allows you to set up various numeric display
    formats through GUI

15
Suppress Output
  • Suppressing Output
  • End of the statement with a semicolon
  • Increase statement and program execution speed
  • An Example
  • gtgt x 10
  • gtgt y 10
  • gtgt product x y
  • Product 100

16
Entering long Statements
  • If a statement does not fit on a line (too long),
    uses an ellipsis (three periods), follow by Enter
    or Return, to indicate the continuation of the
    statement to the next line
  • For an example
  • gtgt x 1 2 3 5 6 7 ...
  • 8 9 10
  • x
  • 51

17
Command Line Editing and Command History
  • Command Line Editing
  • Keys such as right arrow ?, down arrow ?, up
    arrow ?, left arrow ?, etc, can be used to edit
    commands
  • Command History
  • The entered commands at the Command Windows are
    recorded or logged in the Command History
  • We can view previous commands or statements
  • We can copy or execute rerun previous statements

18
The MATLAB Workspace
  • who function
  • whos function
  • clear function

gtgt who Your variables are x y gtgt whos Name
Size Bytes Class x 1x1
8 double array y 1x1
8 double array Grand total is 2
elements using 16 bytes gtgt clear x gtgt who Your
variables are y gtgt clear gtgt whos
19
The MATLAB Workspace
gtgt save 8_20_2004.mat gtgt clear gtgt whos gtgt load
8_20_2004.mat gtgt whos Name Size Bytes
Class ans 1x1 8 double array
x 1x1 8 double array y
1x1 8 double array Grand total
is 3 elements using 24 bytes gtgt clear gtgt whos
  • save function
  • load function

Current Directory
20
Save Command
  • We can use help save to see documentation of
    SAVE function and learn how to Save workspace
    variables to disk.
  • SAVE FILENAME saves all workspace variables to
    the binary "MAT-file, If FILENAME has no
    extension, .mat is assumed.
  • SAVE, by itself, creates the binary "MAT-file"
    named 'matlab.mat'. It is an error if
    'matlab.mat' is not writable.
  • SAVE FILENAME X saves only X.
  • SAVE FILENAME X Y Z saves X, Y, and Z. The
    wildcard '' can be used to save only those
    variables that match a pattern.

21
Save Command (continue)
  • MATLAB also offers various saving options
  • ASCII Options
  • SAVE ... -ASCII uses 8-digit ASCII form instead
    of binary regardless of file extension.
  • SAVE ... -ASCII -DOUBLE uses 16-digit ASCII
    form.
  • SAVE ... -ASCII -TABS delimits with tabs.
  • And more will be discussed later

22
Help Browser
23
Workspace Browser
24
Current Directory Browser
25
The Edit/Debug
  • Use the Editor/Debugger to create and debug
    M-files, which are programs you write to run
    MATLAB functions.
  • The Editor/Debugger provides a graphical user
    interface for basic text editing, as well as for
    M-file debugging.

26
The Edit/Debug (continue)
27
The Edit/Debug (continue)
Create a mlab_exs directory
Save the M-file as sine60hz.m
28
The Edit/Debug (continue)
29
Testing/Debugging sin60hz.m
Click -gt Debug -gt Run
30
Other Commands
  • Other Useful MATLAB Management Commands/Functions
  • demo - Run demos
  • help - Online help
  • ver - Current MATLAB and toolbox versions
  • version - Current MATLAB version number
  • path - MATLAB Search path
  • diary - Save typed commands on a named file

31
Summary
  • Desktop Tools
  • Starting and Quitting MATLAB
  • Command Window
  • Running Functions
  • Entering Variables
  • Controlling Input/Output
  • Searching Items
  • Running Programs
  • Preferences for the Command Window
  • Command History
  • The MATLAB Workspace
  • Help Browser
  • Workspace Browser
  • Current Directory Browser
  • Edit/Debug - a sine wave program

32
Question?
  • Answers
  • Email lin_at_ipfw.edu
Write a Comment
User Comments (0)
About PowerShow.com