Sie sind auf Seite 1von 6

GENN004: Introduction to Computers

09-Feb-13

MATLAB Basics

Overview
MATLAB Desktop Command Window Scripts Practice

MATLAB Basics

GENN004: Introduction to Computers

09-Feb-13

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

MATLAB Desktop
Current Folder Workspace Browser The prompt Function Browser

Help Browser

The Command Window Path Browser

The Command History Window

The Start Button

What are the usages of these items? Try it and take notes

MATLAB Basics

GENN004: Introduction to Computers

09-Feb-13

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.

Command Window

User Input (What you typed) Calculation Results (What MATLAB computed from your statement)

MATLAB Basics

GENN004: Introduction to Computers

09-Feb-13

Command Window
Use the Up and Down keys while in the command window Double click any line in the command history Add semi-colon at the end of your statement in the command window. Type whos in the command window. What do you get? Type clc in the command window. What happened?

Creating Scripts
Change the current folder to C:\ and observe the Path Browser contents Change the current folder to your FirstLastName folder From MATLAB desktop menu select File New Script 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?

MATLAB Basics

GENN004: Introduction to Computers

09-Feb-13

Script Contents
a = 1; b = 5; c = 6; d = sqrt(b^2 - 4*a*c); r1 = (-b - d)/(2*a) r2 = (-b + d)/(2*a) Why to use script?

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

MATLAB Basics

GENN004: Introduction to Computers

09-Feb-13

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 the command window.

Practice
1. Write and execute a script to calculate the area of a rectangle
area=length x width;

2. Write and execute a script to calculate the distance between two points (x1,y1) and (x2,y2)
dist=sqrt((x2-x1)^2+(y2-y1)^2);

3. Write and execute a script to calculate your own equation. (Bonus will be given to good ideas) All scripts should be stored in your FirstLastName folder and have clear names.

MATLAB Basics

Das könnte Ihnen auch gefallen