Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 28

Getting Started with MATLAB

1. 2.

Fundamentals of MATLAB Different Windows of MATLAB

SKNSCOE

Fundamental components of MATLAB

MATLAB stands MATrix LABoratory

MATLAB = a calculator + a lot more

SKNSCOE

Different Windows of MATLAB

Opening MATLAB in a lab: most computer on campus will have a direct shortcut on the desktop

Double Click to bring up the MATLAB Interface

SKNSCOE

Starting Matlab

When you start MATLAB, 4 windows appear (by default): MATLAB Command Window Current Directory Window Workspace Window Command History Window

SKNSCOE

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

ii) Current Directory Window:

It is much like a file manager window. Used to access files.

For example: file.m it will open file in Matlab editor.

SKNSCOE

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

iv) Command History Window:

All the previous keystrokes entered in Matlab Command Window showed here. You can click and drag the command into the Matlab command window or Matlab editor. You can alter the appearance of the desktop by clicking ViewDesktop layout.

SKNSCOE

Frame #2
Current Directory

Frame #3

Frame #1
The Command Window
Your Calculator Screen

Workspace It will show the variables that have been created.

This frame shows the files (excel, text, MATLAB files) that can immediately be used.

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.

Frame #4
Command History

It will show all the commands executed previously.


9

SKNSCOE

MATLAB Desktop

Current Directory

Command Window

History

SKNSCOE

MATLAB Desktop contd

Workspace Command Window

Command History

SKNSCOE

General Setup

12

SKNSCOE

A new window: the Editor

SKNSCOE

A new window: the Editor

14

SKNSCOE

A new window: the Editor

"DOCK IT"

15

SKNSCOE

Final common setup!

16

SKNSCOE

How it will work

1. Type your statements here

2. Run your statements (or hit F5)

(Modify your statements, repeat cycle)

3. See your results here

17

SKNSCOE

1. Basic Data Manipulation

Starting MATLAB on every machine usually leads to the prompt symbols >> in the command window

18

SKNSCOE

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, Matlab will 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

Variables

A variable in MATLAB is a symbol used to contain a value. When we do not specify a variable name for a result, Matlab uses the symbol ans as a temporary variable containing the most recent answer.

Scalar variable: >> r=8/10 r = 0.8000 >> s=5*r s=4

SKNSCOE

Variables
Scalar arithmetic operations:
Operation Symbol ^ * / \ Exponentiation: ab Multiplication: ab Right division: a/b Left division: b/a MATLAB form a^b a*b a/b a\b

+ -

Addition: a+b Subtraction: a-b

a+b a-b

Vectors / Array
>> a=[1 2 3 4] a= 1 >> a' ans = 1 2 3 4 2 3 4

SKNSCOE

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

Matrices Creation in MATLAB


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

SKNSCOE

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

Reshape
>> a=[1:9] a= 1 2 3 4 5 6 7 8 9

>> bsquare=reshape(a,3,3) bsquare = 1 2 3 4 5 6 7 8 9

>>

SKNSCOE

For

for i = 1:10 end

SKNSCOE

xy Plots
>> x=[1 3 6 8 10]; >> y=[0 2 1 3 1]; >> plot(x,y)

SKNSCOE

You might also like