Vous êtes sur la page 1sur 5

1/16/2016

TYPICAL USES OF MATLAB


INTRODUCTION

Maths

and Computation
development
Data acquisition
Modeling, simulation and prototyping
Scientific and engineering graphics
Data analysis, exploration and
virtualization
Application development, including
graphical user interface building

To MATLAB

Algorithms

MATLAB WINDOWS

Default Desktop Environment


Command Window
the main window in which commands are keyed in after the
command prompt >>
Results of most printing commands are displayed in this
window.
Command History Window
This window records all of the executed commands as well
as the date and time when these commands were executed.
This feature comes very handy when recalling previously
executed commands.

2:23 PM

MATrix LABoratory
powerful high-level programming language for
scientific computations.
supports a rich suite of mathematical, statistical and
engineering functions.
functionality is extended with interactive graphical
capabilities for creating 2D as well as 3D plots.
provides comprehensive toolboxes.
Areas in which toolboxes are available include
communications, signal processing, control systems, neural
networks, fuzzy logic, simulation and many more.

Previously entered commands can also be re-invoked using


up arrow key
4

MATLAB WINDOWS

GETTING STARTED

Default Desktop Environment

2:23 PM

Current Directory Window

This window keeps track of the files in the current


directory.

Entering Matrices

A=[1 2 3 4]
Or
A=[1,2,3,4]

Workspace

Row Matrices

This window is used to organize the loaded variables and displays


the information such as size and class of these variables.

Column Matrices

Other matrices.

C=

B=[1;2;3;4]

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

C=[1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]

1/16/2016

Once you have entered the matrix, it is automatically


remembered in the MATLAB workspace. You can refer to it
simply as A.
Default variable is ans
; is used to terminate any command (if you dont want your output
to be displayed)
Sum (C)
ans= 10 26 42 58
Above command generates a row vector which has sum of all the
columns
If you are required to generate a vector which has sum of all rows
in it then?
Convert all the elements of rows into columns and then perform
sum.
By taking transpose you can perform this task easily.

How to generate sum of elements of diagonal?


Sum(diag(C))
Sum of random elements in a matrix.
C(1,4) + C(2,4) + C(3,4) + C(4,4)
You can insert or change a particular value C(2,4) = 5
Now insert C(2,5)?

TRANSPOSE

C=

C generates

1
2
3
4

5 9 13
6 10 14
7 11 15
8 12 16

To display all the elements in the diagonal of a


matrix.
C= 1
2
3 4
diag(C)
5
6
7 8

9 10
13 14

11 12
15 16

Magic(5)
diary lab#02

Type few commands

diary off
format long

If you want complete values


pi

format short
format compact
format loose

COLON(:)

Numbers from 110 will be


1 2 3 4 5 6 7 8 9 10
What's the increment between each number?
1
We call this increment as Step Size
Its easy to type an array or matrix of 10 or eleven elements but
what if you want an array of 100 or 500 elements?
If you want an array of 100 elements just use this format 1:100
A row matrix is created with 1st element 1 and last being 100
What if you want a series of numbers in which step size is other
than 1?
Just insert the amount of step size you want between two limits.
1:10:100

OPERATORS
+
*
/
^

()

Addition
Subtraction
Multiplication
Division
Power
Complex conjugate transpose
Specify evaluation order

1/16/2016

After creating M-File.


A=[1 2 3 4;5 6 7 8;9 10 11 12]
Save it.
In command window type the filename by the name
you saved it.
Now see workspace.
Clear all.

LAB SESSION 1

Objective

To learn plotting of signals in


MATLAB

Mean
Median

SIGNALS REPRESENTATION

Examples:

A vector is plotted against a vector

Two functions

x = [2, 3, -5, -3, 1]


n = 2: :17 = [2, 5, 8, 11, 14, 17]

plot

stem

Step size

lengths of vectors must match

n = 2:17 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17]


Default step size is 1

2:23 PM

A signal in MATLAB is represented by a


row vector:

2:23 PM

PLOTTING IN MATLAB

for CT signals
for DT signals

15

16

EXAMPLES
EXAMPLES

plot(t, x) plot([-2:0.002:2], 10 * sin(pi*[-2:0.002:2]))

title(Example Sinusoid)
xlabel(time(sec))
ylabel(Amplitude)

2:23 PM

Plot the following signal


x = 10sin t

2:23 PM

vector x against vector t

must decide on vectors lengths

t = [-2:0.002:2]
how to generate vector x?
x = 10 * sin (pi * t)

plot(t, x)

Vector on x-axis

Vector on y-axis

17

18

1/16/2016

MULTIPLE PLOTS

GENERATING SUBPLOTS

subplot(2, 3, 2)

19

EXAMPLE

2:23 PM

plot(t, y, r-, t, x, g-);


legend(Sine curve, Cosine curve);

2:23 PM

20

DT PLOTS
Plot the DT sequences:

x = {2, 3, -1, 5, 4, 2, 3, 4, 6, 1}

2:23 PM

2:23 PM

x = [2, 3, -1, 5, 4, 2, 3, 4, 6, 1]
n = -6:3;
stem(n, x);

21

22

ZERO & ONE VECTORS


EXERCISE
Unit Impulse
Unit Step
Unit Ramp
Exponential Sequence

24

zeros(1, 5)
[0 0 0 0 0]
ones(1, 5)
[1 1 1 1 1]

2:23 PM

Generate following elementary DT signals:

2:23 PM

25

1/16/2016

UNIT IMPULSE
n = -5:5;
stem(n, [zeros(1, 5) 1 zeros(1, 5)]);

Generate the following signal for -10<n<10


x = (10cosn)(5cos0.25n)

2:23 PM

2:23 PM

EXERCISE

n = -10:10;
x1 = 10 * cos(pi * n);
x2 = 5 * cos(0.25 * pi * n);
x = x1 .* x2;
stem(n, x);

26

27

Vous aimerez peut-être aussi