01_GENN004m_MATLABBasics

download 01_GENN004m_MATLABBasics

of 6

Transcript of 01_GENN004m_MATLABBasics

  • 7/29/2019 01_GENN004m_MATLABBasics

    1/6

    GENN004: Introduction to Computers 09-Feb-

    MATLAB Basics

    MATLAB Basics

    Overview

    MATLAB Desktop

    Command Window

    Scripts

    Practice

  • 7/29/2019 01_GENN004m_MATLABBasics

    2/6

    GENN004: Introduction to Computers 09-Feb-

    MATLAB Basics

    MATrix LABoratory (MATLAB)

    Create a Folder with your FirstLastName in the

    computer desktop (like ElsayedHemayed) to

    store your work.

    From the Start button (lower left corner of the

    screen), browse the programs, find and start

    MATLAB.

    Explore the MATLAB desktop and take notes

    The Command Window The Command

    History Window

    The Start Button

    Workspace

    Browser

    Path Browser

    Help Browser

    Function Browser

    MATLAB Desktop

    The prompt

    What are the usages of these items?

    Try it and take notes

    Current Folder

  • 7/29/2019 01_GENN004m_MATLABBasics

    3/6

    GENN004: Introduction to Computers 09-Feb-

    MATLAB Basics

    MATLAB Desktop

    Write and calculate simple and complex

    equations in the command window

    Observe the workspace browser and the

    command history. How their contents are

    affected?

    Use the help browser then the function

    browser to learn and to get the square root of

    a number x.

    User Input

    (What you typed)

    Calculation Results

    (What MATLAB computed from your statement)

    Command Window

  • 7/29/2019 01_GENN004m_MATLABBasics

    4/6

    GENN004: Introduction to Computers 09-Feb-

    MATLAB Basics

    Command Window

    Use the Up and Down keys while in thecommand window

    Double click any line in the command history

    Add semi-colon at the end of your statementin the command window.

    Type whos in the command window. What doyou get?

    Type clc in the command window. Whathappened?

    Creating Scripts

    Change the current folder to C:\ and observe the PathBrowser contents

    Change the current folder to your FirstLastName folder

    From MATLAB desktop menu select File NewScript

    Type the following commands in the opened editor

    Save this file as firstProgram

    Click the Green Arrow to run these commands

    Check the output in the command window

    What is the purpose of this script?

  • 7/29/2019 01_GENN004m_MATLABBasics

    5/6

    GENN004: Introduction to Computers 09-Feb-

    MATLAB Basics

    Script Contents

    Why to use script?

    a = 1;

    b = 5;

    c = 6;

    d = sqrt(b^2 - 4*a*c);

    r1 = (-b - d)/(2*a)

    r2 = (-b + d)/(2*a)

    Statements in a program (script) are

    executed in sequence

    % A program fragment ...

    x= 2*3.14

    y= 1+x

    x= 5

    % What is y now?

    6

    7.28

    Other value

  • 7/29/2019 01_GENN004m_MATLABBasics

    6/6

    GENN004: Introduction to Computers 09-Feb-

    MATLAB Basics

    Editing Scripts

    Go to your FirstLastName folder on Windows

    desktop

    Double click to open your firstProgram file

    Edit this script by adding your name at the

    beginning of the script. Use % before your

    name. Why?

    Re-run the script and see the output at thecommand window.

    Practice

    1. Write and execute a script to calculate the area of arectangle

    area=length x width;

    2. Write and execute a script to calculate the distancebetween two points (x1,y1) and (x2,y2)

    dist=sqrt((x2-x1)^2+(y2-y1)^2);

    3. Write and execute a script to calculate your ownequation. (Bonus will be given to good ideas)

    All scripts should be stored in your FirstLastName folderand have clear names.