0% found this document useful (0 votes)
340 views45 pages

Introduction To Matlab

MATLAB is a high-level technical computing language and interactive environment for algorithm development, data visualization, and numeric computation. It allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages. MATLAB contains toolboxes for signal processing, control systems, simulink, computer vision and other domains.

Uploaded by

reddy naveen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
340 views45 pages

Introduction To Matlab

MATLAB is a high-level technical computing language and interactive environment for algorithm development, data visualization, and numeric computation. It allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages. MATLAB contains toolboxes for signal processing, control systems, simulink, computer vision and other domains.

Uploaded by

reddy naveen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 45

Introduction to Matlab

MATLAB
 MATLAB (Matrix Laboratory)
 MATLAB is a high-performance language for technical
computing
 It integrates
 Computation
 Visualization
 Programming, in an easy-to-use environment where problems
and solutions are expressed in familiar mathematical notation.
MATLAB USES
 Math and computation
 Algorithm development
 Data acquisition
 Modeling, simulation, and prototyping
 Data analysis, exploration, and visualization
 Scientific and engineering graphics
 Application development, including GUI building
MATLAB INTRO
 MATLAB is an interactive system whose basic data element is
an array that does not require dimensioning
 Helps to solve technical computing problems, specially those
with matrix and vector formulations, in a fraction of the time
it would take to write a program in a scalar noninteractive
language such as C or Fortran
MATLAB INTRO
 A standard instructional tool for introductory and advanced
courses in mathematics, engineering, and science
 MATLAB is the tool of choice for high-productivity research,
development, and analysis
MATLAB SYSTEM DEVELOPMENT
ENVIRONMENT

MATHAMETICAL
FUNCTIONAL LIB

MATLAB
MATLAB SYSTEM
LANGUAGE

GRAPHICS

API
DEVELOPMENT ENVIRONMENT
 It has some set of tools and facilities that help us to use
MATLAB functions and files
 This includes the following
 MATLAB desktop
 Command Window
 Command history
 Editor and debugger
 Browsers for viewing help
 Workspace, files, and the search path
MATH FUNCTIONAL LIBRARY
 This is a vast collection of computational algorithms ranging
from elementary functions like,
 Sum
 Sine
 Cosine
 Complex arithmetic
 Matrix inverse
 Matrix eigenvalues
 Bessel functions
 Fast Fourier transforms
MATLAB LANGUAGE
 A high-level matrix/array language with
 Control flow statements
 Functions
 Data structures
 Input/output
 Object-oriented programming features
Allows small, large and complex application programs
GRAPHICS
 MATLAB has extensive facilities for displaying vectors and
matrices as graphs, as well as annotating and printing those
graphs
 It includes high-level functions for
 2-D & 3-D data visualization
 Image processing
 Animation
 presentation graphics
 GUI
API

 This is a library that allows you to write C and Fortran


programs that interact with MATLAB

 It includes facilities for


 Calling routines from MATLAB (dynamic linking)
 Calling MATLAB as a computational engine
 For reading and writing MAT-files
Matlab Files
 M file (matlab file)
 .Mdl file (simulink model file)
 .GUI file (Grapical user interface file)
ARITHMATIC OPERATORS
plus - Plus +
uplus - Unary plus +
minus - Minus -
uminus - Unary minus -
mtimes - Matrix multiply *
times - Array multiply .*
mpower - Matrix power ^
power - Array power .^
mldivide - Backslash or left matrix divide \
mrdivide - Slash or right matrix divide /
ldivide - Left array divide .\
rdivide - Right array divide ./
RELATIONAL OPERATORS
eq - Equal ==
ne - Not equal ~=
lt - Less than <
gt - Greater than >
le - Less than or equal <=
ge - Greater than or equal >=
LOGICAL OPERATORS
Short-circuit logical AND &&
Short-circuit logical OR ||
and - Element-wise logical AND &
or - Element-wise logical OR |
not - Logical NOT ~
xor - Logical EXCLUSIVE OR
any - True if any element of vector is nonzero
all - True if all elements of vector are nonzero
BITWISE OPERATORS
bitand - Bit-wise AND
bitcmp - Complement bits
bitor - Bit-wise OR
bitmax - Maximum floating point integer
bitxor - Bit-wise XOR
bitset - Set bit
bitget - Get bit
bitshift - Bit-wise shift
VECTORS
a = [1 2 3 4 5 6 9 8 7] ;

t = 0:2:20
t = 0 2 4 6 8 10 12 14 16 18 20

b=a+2

b = 3 4 5 6 7 8 11 10 9

c=a+b
c = 4 6 8 10 12 14 20 18 16
MATRICES
B = [1 2 3 4;5 6 7 8;9 10 11 12] ;

B=1234
5678
9 10 11 12

C = B'

C=159
2 6 10
3 7 11
4 8 12
BASIC MATRIX OPERATORS
X = inv(E) ;%INVERSE OF THE MATRIX
[A,H] = eig(E) %eigen value &vector
p = poly(E) %polynomial
c = abs(y) ;
D=min(a);
D=max(a);

Convolution
x = [1 2];
y = [1 4 8];
z = conv(x,y)
[xx, R] = deconv(z,y)
PLOT
t=0:0.25:7;
y = sin(t);
plot(t,y)
MATRICES & ARRAYS
 In MATLAB, a matrix is a rectangular array of numbers
 Stores numeric and non-numeric data as matrix
 Where other programming languages work with numbers
one at a time, MATLAB allows us to work with entire
matrices quickly and easily
PLOT
t=0:0.25:7;
y = sin(t);
plot(t,y) ;
xlabel('x axis');
ylabel('y axis');
title('Heading');
grid on;
gtext('text');
IF LOOP
a=6;

if a > 6

disp('a is greater');

elseif a==0

disp('a is zero');

else

disp('a is smaller');

end
FOR LOOP
a=5;

for i=1:5

a=a+1

end

disp(a);

ANS a =10
WHILE LOOP
a=5;

while a < 10
a=a+1;

end

disp(a);
Ans a =10
FUNCTION
function c=add(a,b);
c=a+b; function c=mul(a,b);
return c=a*b;
return

Main
a=5;
b=6;
c=add(a,b);
disp(c);
d=mul(a,b);
disp(d);
SWITCH (NUMERICAL)
a=input('enter---->');
switch a
case 1
fprintf('one');
case 2
fprintf('two');
case 3
fprintf('three');
case 4
fprintf('four');
otherwise
fprintf('otherwise');
end
READ AN IMAGE
a =imread('cameraman.tif'); a =imread('flowers.tif');
imshow(a); imshow(a);
pixval on; pixval on;
READ AN AUDIO FILE

a =wavread('test.wav');
wavplay(a,44100);
Plot(a);
READ A VIDEO FILE

a=aviread('movie.avi');
movie(a);
ADD TWO IMAGES

I = imread('rice.tif'); I = imread('rice.tif');
J = imread('cameraman.tif'); J = imadd(I,50);
K = imadd(I,J,'uint16'); subplot(1,2,1), imshow(I)
imshow(K,[]) subplot(1,2,2), imshow(J)
SUBTRACT TWO IMAGES
I = imread('rice.tif');
Iq = imsubtract(I,50);
subplot(1,2,1), imshow(I)
subplot(1,2,2), imshow(Iq)
CONVERT IMAGE TO GRAY AND BINARY

clc;
clear;
close all
a= imread('flowers.tif');
subplot(2,2,1);
imshow(a);
subplot(2,2,2);
b=imresize(a,[256 256]);
imshow(b);
subplot(2,2,3);
c=rgb2gray(b);
imshow(c);
subplot(2,2,4);
d=im2bw(c);
imshow(d);
RGB COMPONENT
a=imread('flowers.tif');
subplot(2,2,1);
imshow(a);
R=a;
G=a;
B=a;
R(:,:,2:3)=0;
subplot(2,2,2);
imshow(R);
G(:,:,1)=0;
G(:,:,3)=0;
subplot(2,2,3);
imshow(G);
B(:,:,1)=0;
B(:,:,2)=0;
subplot(2,2,4);
imshow(B);
CONVERT IMAGE TO 1-D

a = imread('cameraman.tif');

[r c]=size(a);

Len=r*c;

b=reshape(a,[1 Len]);
CONVER MOVIE TO FRAMES
file=aviinfo('movie1.avi'); % to get inforamtaion abt video file
frm_cnt=file.NumFrames % No.of frames in the video file
str2='.bmp'
h = waitbar(0,'Please wait...');
for i=1:frm_cnt
frm(i)=aviread(filename,i); % read the Video file
frm_name=frame2im(frm(i)); % Convert Frame to image file
frm_name=rgb2gray(frm_name);%convert gray
filename1=strcat(strcat(num2str(i)),str2);
imwrite(frm_name,filename1); % Write image file
waitbar(i/frm_cnt,h)
end
close(h)
CONVERT FRAMES TO MOVIES
frm_cnt=5;
number_of_frames=frm_cnt;
filetype='.bmp';
display_time_of_frame=1;
mov = avifile('MOVIE.avi');
count=0;
for i=1:number_of_frames
name1=strcat(num2str(i),filetype);
a=imread(name1);
while count<display_time_of_frame
count=count+1;
imshow(a);
F=getframe(gca);
mov=addframe(mov,F);
end
count=0;
end
mov=close(mov);
READ A TEXT FILE
fid = fopen('message.txt','r');
ice1= fread(fid);
s = char(ice1');
fclose(fid);
disp(s);

Ans hello
WRITE A TEXT FILE

txt=[65 67 68 69];
fid = fopen('output.txt','wb');
fwrite(fid,char(txt),'char');
fclose(fid);

ANS =ACDE
STORE AN IMAGE,AUDIO
a =imread('cameraman.tif');
imwrite(a,'new.bmp');

a=wavread('test.wav');
wavwrite(d,44100,16,'nTEST.WAV');
SAVE AND LOAD THE VARIABLE
A=5;
save A A;

load A

B=1;
C=A+B;
disp(C);
WAVELET TRANSFORM

a =imread('cameraman.tif');

[LL LH HL HH]=dwt2(a,'haar');

Dec=[...
LL,LH
HL,HH
...
];

imshow(Dec,[]);
DCT TRANSFORM

a=imread('cameraman.tif');
subplot(1,3,1);imshow(a,[]);
b=dct2(a);
subplot(1,3,2);imshow(b,[]);title('DCT');
c=idct2(b);
subplot(1,3,3);imshow(c,[]);title('IDCT');
NOISE AND FILTER

I = imread('eight.tif');
J = imnoise(I,'salt & pepper',0.02);
K = medfilt2(J);
subplot(1,2,1);imshow(J)
subplot(1,2,2);imshow(K)

You might also like