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

MATLAB

Signal Analysis Tutorial (Day-1)


 What is Matlab ?
• Matlab is a programming language.
• Initially developed by a lecturer in 1970’s to
help students to learn linear algebra.
• Its basic data element is the matrix.
• Very simple to code.
• Here we can do mathematical operations and
can represent the output in a matrix from or by
different plots.
Desktop Basics

Current Command Window


Folder

>> command prompt


Work Space
Desktop Basics
• The desktop includes mainly these panels:
• Current Folder — Access your files.
• Command Window — Enter commands at
the command line, indicated by the prompt
(>>).
• Workspace — Explore data that you create or
import from files.
Basic arithmetics
2+2=? Addition
2*3=? Multiplication
3-2=? subtraction
8/2=? 8\2=? division
2^2=?
64^(1/3)=?
 1 4 3 3000 
     ?
 23 5
2
24 
Example
Example
Division
Basic arithmetics
2+2=? Addition
2*3=? Multiplication
3-2=? subtraction
8/2=? 8\2=? division
2^2=?
64^(1/3)=?
 1 4 3 3000 
     ?
 23 5
2
24 
Some codes

When θ is in Degree
Use ------

sind (θ) sine theta


atand(θ) tan inverse

nthroot Real n-th root of real numbers.


Clear all removes all variables
Clc Clear command window
Close all close all window
; separate columns and suppress display
Use of ‘Help’ command
>> power (A,B)

2
3
>>power(3,2)
ans =
9
Exercise
1
1 tan   ?
2 sin 50  cos 50  ?
2 2

 1 4 3 3000 
3
     ? [Using command]
 23 5
2
24 
Variable

f ( x)  ax  bx  c
2

Where a= 3, b=2,c=1; find f(4)=?


Variable

f ( x)  ax  bx  c
2

Where a= 3, b=2,c=1; find f(4)=?


Matrix
• How to write matrix:

Command for matrix [X] which is 3 rows and 3 columns


Basic Matrix Command
zeros(m) matrix with all zero value
eye(m) eigen matrix
ones(m,n) matrix with all one value
rand(m,n) matrix with all random value
rank(A) show the rank of matrix A
det(A) to calculate determinant
Matrix addition
Exercise

=?
Matrix transpose
Matrix multiplication
Matrix multiplication
Matrix multiplication
Matrix multiplication
Matrix inverse
Extraction of rows or columns
Exercise
Plots
Plotting commands
Example

title('Actual gravity Data');


xlabel('Longitude (degree)');
ylabel('Latitude (degree)');
clrbr=colorbar;
ylabel(clrbr, 'gravity
anomaly (in mgal)');
exercise
• x = 0:2*pi;
• y1 = 2*cos(x);
• y2 = cos(x);
• y3 = 0.5*cos(x);
• plot(x,y1,'--',x,y2,'-',x,y3,':')
• xlabel(‘the value of x')
• ylabel('Cosine functions')
• legend('2*cos(x)','cos(x)','0.5*cos(x)')
• title('Typical example of multiple plots')
• axis([0 2*pi -3 3])
• x = 0:pi/100:2*pi;
• y1 = 2*cos(x);
• y2 = cos(x);
• y3 = 0.5*cos(x);
• plot(x,y1,'--',x,y2,'-',x,y3,':')
• xlabel('the value of x')
• ylabel('Cosine functions')
• legend('2*cos(x)','cos(x)','0.5*cos(x)')
• title('Typical example of multiple plots')
• axis([0 2*pi -3 3])
Scripts
• Scripts are basically used to execute several commands
at a time.

Name of the Editor window to write


MATLAB code or command lines
file
Scripts
• To run:
Write the code > save the code > press run

**Script file should not named as


standard functions of MATLAB
Plots in scripts

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