Вы находитесь на странице: 1из 79

1.

Introduction
2. The MATLAB environment
3. MATLAB Basics
4. Branching Statements
5. Loops
6. Plotting graphs
7.Advantages of MATLAB
8. Disadvantages of MATLAB
9. Conclusion
10. Bibliography
Introduction
MATLAB (short for MATrix LABoratory)

Much richer than any other technical


programming language.
The MATLAB
Environment
The MATLAB Desktop
1. The Command Window
2. The Command History Window
3. The start button
4. The document window, including the
editor/ Debugger & Array editor
5. The figure windows
6. The workspace browser
7. The help browser
8. The path browser
 
MATLAB basics
 Variables

 Arrays

 Vectors

 Matrices
1.Variables and Arrays
Initializing Variables in
Assignment Statements
An assignment statement has general form
var = expression
* var = 40i;
* var = var/5;
* array = [1 2 3 4];
* x = 1; y = 2;
* a = [0 1+7]; b = [a(2) 7 a];
There a = [0 8] & b = [8 7 0 8]
---- echoing------
If a semicolon is added at the end of
statement
echoing disappears.

 It occurs due to the absence of semicolon in


the
end of instruction.
Initializing with Shortcut
Expression

colon operator: first : incr : last

>> x = 1 : 2 : 10
x=
1 3 5 7 9
Initializing with Built-In-
Function

 Arrays can be initialized using the Built-In-


Functions. For example the function ‘zeros’ can
be used to create an all-zero array of any
desired size.
 If the functions have two arguments then 1st
one will be the no. of rows and the 2nd one be
the no. of columns.
v.a = zeros (2);
vi.b = zeros(2,3);
vii.c = [1 2; 3 4];
2. Scalar and Array operations
Arithmetic Operations
 Addition a+b
 Subtraction a-b
 Multiplication a*b
 Division a/b
 Exponential a^ b
Scalar operation
 2^((8+2)/5)=2^(10/5)
 =2^2
 =4
3. Array and Matrix Operations

 Array operations may also occur


between an array and a scalar. If the
operation is performed between an array and
scalar, the value of the scalar is applied to
every element of the array.
 In contrast, Matrix Operations follow the
normal rules of linear algebra, such as matrix
multiplication.
Operations
Syntax
Array Addition a +
b
Array Subtraction a - b
Array Multiplication a .*
b
Array Right Division a ./
b
Array Left Division a .\
b
Matrix Right Division a /
b
Matrix left Division a \
b
The Logic Data type
The logic data type is a special type of
data that can have one of only two possible
values: true or false. These values are
produced by two special functions true or
false. They are also produced by MATLAB
operators: relational operator and logical
operator

1. Relational Operators:
The general form of relational operator is:
a1 op a2
Operator Operation

== equal to
~= not equal to
> Greater than
< less than
>= greater than equal
to
<= less than equal to
Logical Operator
Logical operators are operators with one or two
logical operands that yields a logical
results.There are 5 binary logical operators:
AND, inclusive OR, and exclusive OR, and one
unary operator: NOT.
The general form of logic binary operation is
l1 op l2
And the general form of unary logic operation is
Op l1
Where l1 & l2 are expressions & variables and
op is one of the logic operators
Branching Statements
and Program Design
 The if Construct
The if construct has form:
If control_expr_1
Statement 1
Statement 2
....
else if control_expr_2
statement 1
statement 2
....
else
statement 1
statement 2
....
End
 The switch construct
Switch ( switch_expr)
Case case_expr_1,
Statement 1
Statement 2
...
Case case_expr_2,
Statement 2
Otherwise,
Statement 2
End
The For Loop
for index = expr
statement 1
...
end
MATLAB input and output functions
Category Function
Description
Load/Save Workspace load Load
workspace.
Save Save
Workspace.
File Opening and Closing fopen Open
file.
Fclose Close file.
Binary I/O fread Read binary
data from file
Fwrite Write binary
data to file.
Formatted I/O fscan Read formatted
data from.
fprintf Write formatted
data to file.
fget l Read line from
file, discard new line character.
fget s Read line from
file, keep newline character.
File Positioning, Status, delete Delete file.
exist Check for
existence of a file.
ferror Inquire I/O error
status
feof Test for end of
file.
Plotting graphs
15

10

­5

­10
0 1 2 3 4 5 6 7 8 9 10
plot of y=x.2­10.*x+15
15

10

5
y

­5

­10
0 1 2 3 4 5 6 7 8 9 10
x
1

0.9

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Logarithmic scales
Matlab has provided a way to convert the
normal graphical area in to a logarithmic
graphical area .

semilogx- for getting x axis on logarithmic


scale

semilogy – for getting y axis on logarithmic


scale
50

100

150

200

250

300

350

400

450

100 200 300 400 500 600


rd'
Original Duller
Combined
Program for Frequency Modulation
 --
 >> %-- 10/1/06 9:38 AM --%
 % frequency modulation and demodulation
 %Y= MODULATE(X, Fc, Fs, 'fm', OpT)
 fc=10000;
 fs=100000;
 f1=200;f2=500;
 t=0:1/fs:((2/f1)-(1/fs));
 x1=cos(2*pi*f1*t);
 x2=cos(2*pi*f1*t)+cos(2*pi*f2*t);
 kf=2*pi*(fc/fs)*(1/max(max(x1)));
 kf=kf*(f1/fc);
 %- MODULATION
 opt=10*kf;
 y1=modulate(x1,fc,fs,'fm',opt);
 subplot(521);plot(x1); title('originalsingle tone messaga, fs=100000' )
 subplot(524);plot(y1);title('time domain FM,signal tone,fc=10000,fm=200,
dev=10*fm')
 fx1 = abs(fft(y1,1024));
 fx1 =[fx1(514:1024) fx1(1:513)];
 f=(-511*fs/1024):(fs/1024):(512*fs/1024);
 subplot(524);plot(f,fx1);title('freq. description,single tone,dev=10*fm')
 %demodulation
 x1_recov=demod(y1,fc,fs,'fm',opt);subplot(523);plot(x1_recov);
 >> title('time domain recoverd, single tone, dev=10*fm')
ADVANTAGES
Ease of use

Platform independent

Predefined functions

Device- independent plotting

MATLAB compiler
DISADVANTGES
CONCLUSION
MATLAB is so much powerful that it can handle any
of the
Technical computing.

It is easy to use, so any technician can use it in their


work

It helps a lot in any type of image ,speech and many


types
of processing.
Bibliography

Вам также может понравиться