00 getting started with matlab

Upload: sordfish143

Post on 03-Jun-2018

241 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 00 Getting Started With Matlab

    1/28

    Getting Started withMATLAB

    1. Fundamentals of MATLAB

    2. Different Windows of MATLAB

    1

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    2/28

    Fundamental components of

    MATLAB

    MATLAB standsMATrix LABoratory

    MATLAB = a calculator + a lot more

    2

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    3/28

    Different Windows of MATLAB

    Opening MATLAB in a lab: most computer on campus

    will have a direct shortcut on the desktop

    3

    Double Click to

    bring up the

    MATLAB

    Interface

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    4/28

    Starting Matlab

    When you start MATLAB, 4 windows appear (by

    default):

    MATLAB Command Window

    Current Directory Window

    Workspace Window

    Command History Window

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    5/28

    i) MATLAB Command Window:

    To communicate with MATLAB program, use MATLAB

    command window.

    MATLAB display the prompt (>> ) to indicate that it is

    ready to receive instructions.

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    6/28

    ii) Current Directory

    Window:

    It is much like a file manager window.

    Used to access files.

    For example: file.mit will open file in Matlab editor.

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    7/28

    iii) Workspace Window:

    Display the variables created in the command window.

    Workspace refers to the names and values of any

    variable in-use in the current work session.

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    8/28

    iv) Command History

    Window:

    All the previous keystrokes entered in MatlabCommand Window showed here.

    You can click and drag the command into theMatlab command window or Matlab editor.

    You can alter the appearance of the desktop byclicking ViewDesktop layout.

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    9/28

    9

    Frame #1The Command Window

    Frame #2CurrentDirectory

    Frame #3

    Workspace

    Frame #4Command History

    Your Calculator Screen

    You can do exactly as on your

    calculator: add, subtract, divide,

    multiple, use parentheses to

    override the order of operations

    Later on, you will realize you can do

    a LOT more in this frame.

    This frame

    shows the

    files (excel,

    text,MATLAB

    files) that

    can

    immediately

    be used.

    It will show the

    variables that have

    been created.

    It will show all the

    commands

    executed

    previously.

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    10/28

    MATLAB Desktop

    Command

    Window

    Current

    Directory

    History

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    11/28

    MATLAB Desktopcontd

    Command

    Window

    Workspace

    CommandHistory

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    12/28

    General Setup

    12

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    13/28

    A new window: the Editor

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    14/28

    A new window: the Editor

    14

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    15/28

    A new window: the Editor

    15

    "DOCK IT"

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    16/28

    Final common setup!

    16

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    17/28

    How it will work

    17

    1. Type your statements here

    2. Run your statements

    (or hit F5)

    3. See your results here

    (Modify your statements, repeat cycle)

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    18/28

    1. Basic Data Manipulation

    Starting MATLAB on every machine usually leads to the prompt

    symbols>> in the command window

    18

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    19/28

    Entering Commands and

    Expressions:

    Try out this 3-line command in Matlab Command Window:

    >> x=[0:002:8];

    >> y=5*sin(x);

    >> plot(x,y):

    When you put semicolon (;) at the end of your command line, Matlabwill not shows the answer of your commands/expressions.

    Example of mathematical expressions in Matlab prompt:

    >> 8/10 ans = 0.8000

    >> 5*ans

    ans = 4

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    20/28

    Variables

    A variable in MATLAB is a symbol used to contain avalue.

    When we do not specify a variable name for a result,

    Matlab uses the symbol ans as a temporary variablecontaining the most recent answer.

    Scalar variable:

    >> r=8/10

    r = 0.8000 >> s=5*r

    s = 4

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    21/28

    Variables

    Scalar arithmetic operations:

    Symbol

    Operation MATLAB form

    ^ Exponentiation: ab a^b

    * Multiplication: ab a*b

    / Right division: a/b a/b

    \ Left division: b/a a\b

    + Addition: a+b a+b

    - Subtraction: a-b a-b

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    22/28

    Vectors / Array

    >> a=[1 2 3 4]

    a =

    1 2 3 4

    >> a'

    ans =

    12

    3

    4

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    23/28

    Autofilling and addressing

    Vectors

    > a=[1:0.2:3]'

    a =

    1.0000

    1.2000

    1.4000

    1.6000

    1.8000

    2.0000

    2.2000

    2.4000

    2.6000

    2.8000

    3.0000

    >> a(2:3)

    ans =

    1.2000

    1.4000

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    24/28

    Matrices Creation in MATLAB

    >> b=[1 2 3 4;5 6 7 8]

    b =

    1 2 3 4

    5 6 7 8

    >> b'

    ans =

    1 52 6

    3 7

    4 8

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    25/28

    Matrices

    >> b=2.2*ones(4,4)

    b =

    2.2000 2.2000 2.2000 2.2000

    2.2000 2.2000 2.2000 2.2000

    2.2000 2.2000 2.2000 2.2000

    2.2000 2.2000 2.2000 2.2000

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    26/28

    Reshape

    >> a=[1:9]

    a =

    1 2 3 4 5 6 7 8 9

    >> bsquare=reshape(a,3,3)

    bsquare =

    1 4 7

    2 5 83 6 9

    >>

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    27/28

    For

    for i = 1:10

    end

    SKNSCOE

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1
  • 8/12/2019 00 Getting Started With Matlab

    28/28

    xy Plots

    >> x=[1 3 6 8 10];

    >> y=[0 2 1 3 1];

    >> plot(x,y)

    http://images.google.com/imgres?imgurl=http://www.utm.edu/departments/cens/engineering/Images/matlab_logo_000.gif&imgrefurl=http://www.utm.edu/departments/cens/engineering/tutorials.php&usg=__HD_1gy8R3MAfYqGGEzpzS23GoaQ=&h=420&w=560&sz=33&hl=en&start=1&um=1&itbs=1&tbnid=luK1qGow7LqkwM:&tbnh=100&tbnw=133&prev=/images?q=Matlab&hl=en&rls=com.microsoft:en-us&sa=N&um=1