Exp 1
Exp 1
Exp 1
Aim: To learn the effective MATLAB in-built functions and the image processing basic commands
in MATLAB.
Theory:
Command-1: ‘clc’
‘clc’ stands for clear command window. It will clear any instructions that are present in the
command window.
Fig: 1 Use of “clc” in MATLAB.
Command-2: ‘clf’
‘clf’ stands for clear any existing figure window so the display of
the current program will be on a new axes window.
Example:
Img = imread('coins.png');
figure;imshow(Img);
The command “clear all” will clear all the variables from the MATLAB memory. The command
“clear” removes all variables from the workspace.
Matrix1 = [1 2 3; 4 5 6]
Matrix1
As shown above “close(gcf)” will close the current figure window where “gcf” stands to get the
current figure.
In MATLAB if semicolon is not used at the end of each command line syntax, the MATLAB
will display the output of that line in the command window. Use of semicolons prevents
MATLAB from displaying line by line results in the command window.
1 2 3 4 5 6 7 8
9 10
Colon operator acts as a separator here and produces numbers from 1 to 10.
>> Vector2 = 1:2:10
Vector2 =
1 3 5 7 9
Here the numbers from 1 to 10 in step increment of 2 are generated by the MATLAB.
Arrays and matrices can be defined in many ways in MATLAB. Most of the arrays and matrices
are usually initialized before they are called anywhere in the program.
Array1 = [1:3;4:6]
Array1 =
1 2 3
4 5 6
The above example shows how arrays can be generated in MATLAB using the colon operator.
In MATLAB often use zeros and ones to initialize many variables. For this MATLAB provides
two inbuilt functions namely ‘zeros’ and ‘ones’.
>> X = zeros(2,2)
X=
0 0
0 0
>> Y = ones(1,3)
Y=
1 1 1
Here MATLAB initializes X with a zero matrix of size 2 rows and 3 columns and Y with ones of
size 1 row and 3 columns.
Trigonometry and Geometric Functions in MATLAB
MATLAB supports most of the common trigonometric, algebraic, complex and geometric
functions of Mathematics.
Y = sin(0:2*pi/10:2*pi)
Y=
Columns 1 through 9
Columns 10 through 11
-0.5878 -0.0000
One of the most powerful features of MATLAB is its graphical visualization. MATLAB
provides many features for plotting and representing graphs.
Y = sin(0:2*pi/10:2*pi);figure;plot(Y);
Example:2
x= 1:10;
y1 = sin(x);
y2 = sin(2*x);
y3 = sin(4*x);
y4 = sin(8*x);
figure; subplot(2,2,1);
subplot(2,2,3);plot(x,y3);title('Subplot 3: sin(4x)');
subplot(2,2,4);plot(x,y4);title('Subplot 4: sin(8x)');
In the above example the subplot enables viewing of multiple plots in one window.
“subplot(2,2,X)” represents a plotting window for 4 figures with 2 rows, 2 columns and X denoting
the position of each graph.
Example:3
Y = sin(0:2*pi/10:2*pi);
xlabel('X-Axis');
ylabel('Y-Axis');
title('Sine Wave');
2 clc;clear;
Img = imread('coins.png');
figure; imshow(Img);
resizedimage = imresize(Img,[100 100]);
imshow(resizedimage);
3 clc; clear;
Img = imread('coins.png');
figure;imshow(Img);
close all;
4
Y = sin(0:2*pi/10:2*pi) figure; plot(Y);
6
Y = sin (0:2*pi/10:2*pi);
figure; plot(Y,'b--*','LineWidth',1.5, 'MarkerSize', 10);
xlabel('X-Axis'); ylabel('Y-Axis'); title ('Sine Wave')
7
clc; clf; close all; clear; x = -10:10;
y1 = zeros(1,21); y1(1,11) = 1; y2= zeros(1,21); y2(1,11:21) = 1; y3 = 0:10;
y4 = exp(0:2*pi/10:2*pi); y5= exp(-(0:2*pi/10:2*pi)); y6= sin(0:2*pi/10:2*pi);
subplot(3,2,1); stem(x,y1,'b','filled'); title('Unit Impulse');
subplot(3,2,2); stem(x,y2,'b', 'filled'); title('Unit Step');
subplot(3,2,3); stem(y3,y3, 'b', 'filled'); title('Unit Ramp');
subplot(3,2,4); stem(y3,y4, 'b', 'filled'); title('Exponential Increasing');
subplot(3,2,5); stem(y3,y5, 'b', 'filled'); title('Exponential Decreasing');
subplot(3,2,6); stem(y3,y6, 'b', 'filled'); title('Sinusoid');
Pre Lab Questions:
Q2. What are toolboxes available in MATLAB for image and video processing?
Q1. How to select a fixed element from a matrix in Matlab? Explain with examples
Q2. How do you plot two graphs on the same figure window? Explain with examples
RESULT:
The experiment was successfully completed and the observations and readings were recorded and verified.