SlideShare a Scribd company logo
1 of 39
An IndustrialTrainingReport on MATLAB 1
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
INTRODUCTION TO MATLAB
Version-R2008b
MATLAB is a high level language for technical computing .It stands for
MATrices Laboratory . It is interactive environment for computing, visualizing
and programming .It is a purely algorithm based language , scientific ,
programming based language .With the use of MATLAB we can analyze data,
create model and develop algorithm ,Process on signals, in communications, in
An IndustrialTrainingReport on MATLAB 2
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
image processing, in speech processing and in control systems we use
MATLAB as a tool.
Getting started
MATLAB is available on department machines. You can also download
MATLAB for your personal machine from http://software.caltech.edu.
Type “matlab” at the Unix prompt to start. This will open the MATLAB
desktop, which includes interactive menus and windows in addition to the
command window. You can also start a command prompt-only version of
MATLAB (useful if you are logged in remotely) by typing “matlab –
nodesktop”.
Using MATLAB
The best way to learn to use MATLAB is to sit down and try to use it. In this
handout are a few examples of basic MATLAB operations, but after you’ve
gone through this tutorial you will probably want to learn more. Check out the
“Other Resources” listed at the end of this handout. The Beginning When you
start MATLAB, the command prompt “>>” appears. You will tell MATLAB
what to do by typing commands at the prompt. Creating matrices the basic data
element in MATLAB is a matrix. A scalar in MATLAB is a 1x1 matrix, and a
vector is a 1xn (or nx1) matrix.
For example, create a 3x3 matrix A that has 1’s in the first row, 2’s in the
second row, and 3’s in the third row:
>> A = [1 1 1; 2 2 2; 3 3 3]
The semicolon is used here to separate rows in the matrix. MATLAB gives you:
A =
1 1 1
2 2 2
3 3 3
If you don’t want MATLAB to display the result of a command, put a
semicolon at the end:
>> A = [1 1 1; 2 2 2; 3 3 3];
Matrix A has been created but MATLAB doesn’t display it. The semicolon is
necessary when you’re running long scripts and don’t want everything written
out to the screen! Suppose you want to access a particular element of matrix A:
>> A(1,2)
ans =
1
An IndustrialTrainingReport on MATLAB 3
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
Suppose you want to access a particular row of A:
>> A(2,:)
ans =
2 2 2
The “:” operator you have just used generates equally spaced vectors. You can
use it to specify a range of values to access in the matrix:
>> A(2,1:2)
ans =
2 2
You can also use it to create a vector:
>> y = 1:3
y =
1 2 3
The default increment is 1, but you can specify the increment to be something
else:
>> y = 1:2:6
y =
1 3 5
Here, the value of each vector element has been increased by 2, starting from 1,
whileless than 6. You can easily concatenate vectors and matrices in MATLAB:
>> [y, A(2,:)]
ans =
1 3 5 2 2 2
You can also easily delete matrix elements. Suppose you want to delete the 2nd
element of the vector y:
>> y(2) = []
y =
1 5
MATLAB has several built-in matrices that can be useful. For example,
zeros(n,n) makes an nxn matrix of zeros.
>> B = zeros(2,2)
B =
0 0
0 0
A few other useful matrices are:
zeros – create a matrix of zeros
ones – create a matrix of ones
rand – create a matrix of random numbers
An IndustrialTrainingReport on MATLAB 4
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
eye – create an identity matrix
Matrix operations
An important thing to remember is that since MATLAB is matrix-based, the
multiplication operator “*” denotes matrix multiplication. Therefore, A*B is not
the same as multiplying each of the elements of A times the elements of B.
However, you’ll probably find that at some point you want to do element-wise
operations (array operations). In MATLAB you denote an array operator by
playing a period in front of the operator. The difference between “*” and “.*” is
demonstrated in this example:
>> A = [1 1 1; 2 2 2; 3 3 3];
>> B = ones(3,3);
>> A*B
ans =
3 3 3
6 6 6
9 9 9
>> A.*B
ans =
1 1 1
2 2 2
3 3 3
Other than the bit about matrix vs. array multiplication, the basic arithmetic
operators in MATLAB work pretty much as you’d expect. You can add (+),
subtract (-), multiply (*), divide (/), and raise to some power (^).
MATLAB provides many useful functions for working with matrices. It also
has many scalar functions that will work element-wise on matrices (e.g., the
function sqrt(x) will take the square root of each element of the matrix x).
Below is a brief list of useful functions. You’ll find many, many more in the
MATLAB help index, and also in the “Other Resources” listed at the end of this
handout.
Useful matrix functions:
A’ – transpose of matrix A. Also transpose(A).
det(A) – determinant of A
eig(A) – eigenvalues and eigenvectors
inv(A) – inverse of A
svd(A) – singular value decomposition
norm(A) – matrix or vector norm
find(A) – find indices of elements that are nonzero. Can also pass an
An IndustrialTrainingReport on MATLAB 5
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
expression to this function, e.g. find(A > 1) finds the indices of elements of
A greater than 1.
A few useful math functions:
sqrt(x) – square root
sin(x) – sine function. See also cos(x), tan(x), etc.
exp(x) – exponential
log(x) – natural log
log10(x) – common log
abs(x) – absolute value
mod(x) – modulus
factorial(x) – factorial function
floor(x) – round down. See also ceil(x), round(x).
min(x) – minimum elements of an array. See also max(x).
besselj(x) – Bessel functions of first kind
MATLAB also has a few built-in constants, such as pi (π) and i (imaginary
number). Symbolic math Although MATLAB is primarily used for numerical
computations, you can also do symbolic math with MATLAB. Symbolic
variables are created using the command “sym.”
>> x = sym(‘x’);
Here we have created the symbolic variable x. If it seems kind of lame to you to
have to type in all this just to create “x”, you’re in luck—MATLAB provides a
shortcut.
>> syms x
This is a shortcut for x = sym(‘x’).
Symbolic variables can be used for solving algebraic equations. For example,
suppose we want to solve the equation “x^4 + 3*x^2 + 3 = 5”:
>> y = solve('x^4 + 3*x^2 + 3 = 5',x)
y =
-1/2*(-6+2*17^(1/2))^(1/2)
1/2*(-6+2*17^(1/2))^(1/2)
-1/2*(-6-2*17^(1/2))^(1/2)
An IndustrialTrainingReport on MATLAB 6
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
1/2*(-6-2*17^(1/2))^(1/2)
Since MATLAB is solving for x, a symbolic variable, it writes the answer in
symbolic form. That means that the solutions is written out as an expression
rather than computed as a decimal value. If you want the decimal value, you
need to convert to a double:
>> double(y)
ans =
-0.7494
0.7494
0 - 1.8872i
0 + 1.8872i
However, sometimes you may want to see the symbolic expression. In that case,
you might want MATLAB to write it out in a way that’s easier to read. For this,
use the command “pretty”:
>> pretty(y)
[ 1/2 1/2]
[- 1/2 (-6 + 2 17 ) ]
[ ]
[ 1/2 1/2 ]
[ 1/2 (-6 + 2 17 ) ]
[ ]
[ 1/2 1/2]
[- 1/2 (-6 - 2 17 ) ]
[ ]
[ 1/2 1/2 ]
[ 1/2 (-6 - 2 17 ) ]
Below are a few useful things you can do with symbolic variables in MATLAB.
For more, look at the “Symbolic Math Toolbox” section of the MATLAB help.
solve – symbolic solution of systems of algebraic equations
int(f,x) – indefinite integral of f with respect to x
int(f,x,a,b) – definite integral of f with respect to x from a to b.
diff(f,’x’) – differentiate f with respect to x
taylor – Taylor series expansion of symbolic expression
An IndustrialTrainingReport on MATLAB 7
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
Features of Matlab
 It is easy to learn.
 It is an oop (object oriented programming) language.
 It has less syntax so less errors.
 In Matlab there is no need of declare data types and variable.
 It can be use as a programming language.
 Errors are interpreted by MATLAB.
 We can simulate, model and control with help of Matlab.
Different types of windows according to their use are following
 Command Windows
 Command History
 Current Directory
 Workspace
 Figure Editor
 Editor
Command Window- Command Window The window where you type
commands and non-graphic output is displayed. A ‘>>’ prompt shows you the
system is ready for input. The lower left hand corner of the main. window also
displays ‘Ready’ or ‘Busy’ when the system is waiting or calculating. Previous
commands can be accessed using the up arrow to save typing and reduce errors.
Typing a few characters restricts this function to commands beginning with
those characters.
Workspace- Shows the all the variables that you have currently defined and
some basic information about each one, including its dimensions, minimum,
An IndustrialTrainingReport on MATLAB 8
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
and maximum values. The icons at the top of the window allow you to perform
various basic tasks on variables, creating, saving, deleting, plotting, etc. Double-
clicking on a variable opens it in the Variable or Array Editor. All the variables
that you’ve defined can be saved from one session to another using File>Save
Workspace As (Ctrl-S). The extension for a workspace file is .mat.
Command History-Records commands given that session and recent
sessions. Can be used for reference or to copy and paste commands.
Current directory- The directory (folder) that MATLAB is currently
working in. This is where anything you save will go by default, and it will also
influence what files MATLAB can see. You won’t be able to run a script that
you saved that you saved in a different directory (unless you give the full
directory path), but you can run one that’s in a sub-directory. The Current
Directory bar at the top centre of the main window lets you change directory in
the usual fashion — you can also use the UNIX commands cd and pwd to
navigate through directories. The Current Directory window shows a list of all
the files in the current directory.
Editor-The window where you edit m-files — the files that hold scripts and
functions that you’ve defined or are editing — and includes most standard
word-processing options and keyboard shortcuts. It can be opened by typing
edit in the Command Window. Typing edit myfile will open myfile.m for
editing. Multiple files are generally opened as tabs in the same editor window,
but they can also be tiled for side by side comparison. Orange warnings and red
errors appear as underlining and as bars in the margin. Hovering over them
provides more information; clicking on the bar takes you to the relevant bit of
text. Also remember that MATLAB runs the last saved version of a file, so you
have to save before any changes take effect.
An IndustrialTrainingReport on MATLAB 9
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
Figure Editor-MATLAB opens figures in separate windows, which includes
the ability to fine-tune the appearance of the plot, zoom, etc. You can also use
the Data Cursor to extract values and save them to the Workspace. See the Help
documentation for further detail. The figures can also be saved in a wide variety
of formats — it’s usually a good idea to save them as an m-file (File>Generate
M-file) if there’s any chance at all you might want to modify the figure later and
you haven’t already saved the generating code in a m-file.
Different types of files in Matlab
.m files-when we write program and store in matlab the program is stored in .m
extension.
M-files and functions
If you are doing a computation of any significant length in MATLAB, you will
probably want to make an m-file. Anything that you would type at the command
An IndustrialTrainingReport on MATLAB 10
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
prompt you can put in the m-file (for example, “script.m”) and then run it all at
once (by typing the name of the m-file, e.g. “script”, at the command prompt).
You can even add comments to your m-file, by putting a “%” at the beginning
of a comment line. You can also use m-files to create your own functions. For
example, suppose you want to make a function that increments the value of each
element of a matrix by some constant. And suppose you want to call the
function “incrementor.” You would make an m-file called “incrementor.m”
containing the following:
function f = incrementor(x,c)
% Incrementor adds c to each element in the matrix x
.mat files- MAT-files are double-precision, binary , MATLAB format files.
They can also be manipulated by other programs external to MATLAB.
.fig files-It is extension of figure or graphical or interface files created in
matlab.
.asv files –It is auto save file or back up files which are automatically saved
along with our original files as a backup.
Desktop Tools and Development Environment
Command Work
exit - Terminates the current MATLAB session.
quit -Terminates the current MATLAB session.
Clc- Clear Command Window
Commandhistory- Open Command History window, or select it if already
open.
diary -Save session to file.
Clear- Removes all variables from the workspace. This frees up
system memory.
help -Help lists all primary help topics in the Command Window
An IndustrialTrainingReport on MATLAB 11
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
exist- Check existence of variable, function, directory, or Java class
dir- Directory listing.
What- List MATLAB files in current directory.
Operations in MATLAB:
+ Addition
+ Unary plus
- Subtraction
- Unary minus
* Matrix multiplication
^ Matrix power
 Backslash or left matrix divides
/ Slash or right matrix divide
' Transpose
.' Nonconjugated transpose
.* Array multiplication (element-wise)
.^ Array power (element-wise)
. Left array divide (element-wise)
./ Right array divide (element-wise)
An IndustrialTrainingReport on MATLAB 12
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
Data Analysis commands in MATLAB
 mean:- mean (A) returns the mean values of the elements along different
dimensions of an array.
 median:- returns the median values of the elements along different
dimensions of an array.
 conv:- conv(u,v) convolves vectors u and v. Algebraically, convolution is
the same operation as multiplying the polynomials whose coefficients are
the elements of u and v.
 convn:- convn(A,B) computes the N-dimensional convolution of the
arrays A and B. The size of the result is size(A)+size(B)-1.
 deconv:- deconv(v,u) deconvolves vector u out of vector v, using long
division. The quotient is returned in vector q and the remainder in vector r
such that v = conv(u,q)+r .
 poly:- poly(r) where r is a vector returns a row vector whose elements are
the coefficients of the polynomial whose roots are the elements of r.
 polyval:- polyval(p,x) returns the value of a polynomial of degree n
evaluated at x.
 polyvalm:- polyvalm(p,X) evaluates a polynomial in a matrix sense. This
is the same as substituting matrix X in the polynomial p.
 roots:- returns a column vector whose elements are the roots of the
polynomial c.
 fft:-Discrete Fourier transform.
 fft2:-2-D discrete Fourier transform.
 fftn:-N-D discrete Fourier transform.
An IndustrialTrainingReport on MATLAB 13
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
 ifft:-Inverse discrete Fourier transform.
 ifft2:-2-D inverse discrete Fourier transform.
 ifftn:-N-D inverse discrete Fourier transform.
Graphics commands:
plot:- plot(Y) plots the columns of Y versus their index if Y is a real number.
plot3:- The plot3 function displays a three-dimensional plot of a set of data
points.
subplot:- divides the current figure into rectangular panes that are numbered
row wise. Each pane contains an axes object. Subsequent plots are output to
the current pane.
stem: - Plot discrete sequence data.
3-D Visualization Commands:-
 surf:- surf(Z) creates a three-dimensional shaded surface from the z
components in matrix Z.
 mesh:- mesh, meshc, and meshz create wireframe parametric surfaces
specified by X, Y, and Z, with color specified by C.
 colormap:- A colormap is an m-by-3 matrix of real numbers between 0.0
and Each row is an RGB vector that defines one color.
 zoom:-Turn zooming on or off or magnify by factor.
 rotate3d:- Rotate 3-D view using mouse.
 xlabel, ylabel, zlabel:-Label x-, y-, and z-axis.
 contour:-Contour plot of matrix.
An IndustrialTrainingReport on MATLAB 14
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
 contour3:- 3-D contour plot.
 hist:-Histogram plot.
 sphere:-Generate sphere.
MATLAB Toolboxes:
Toolboxes are collections of functions etc. for
tackling particular classes of problems. They have to be purchased separately to
use with MATLAB to increase its capabilities.
MATLAB contains the following Toolboxes:
 SIMULINK Toolbox
 Image Processing Toolbox
 Control Systems Toolbox
 Signal Processing Toolbox
 Fuzzy Logic Toolbox
 Neural Networks Toolbox
 Optimisation Toolbox
 Statistics Toolbox
 Symbolic maths Toolbox
 Mapping Toolbox
 Wavelet and many more.
An IndustrialTrainingReport on MATLAB 15
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
IMAGE PROCESSING IN MATLAB
Image processing toolbox:
Image:
 An image may defined as a 2-dimensional function, f (x,y), where x & y
are spatial (plane) coordinates, & the amplitude of f at any pair of
coordinates (x,y) is called the intensity or gray level of the image at that
point. When x,y & the amplitude values of f are all finite, discrete
quantities, we call the image as Digital image.
 A digital image differs from a photo in that the values are all discrete.
 A digital image can be considered as a large array of discrete dots, each
of which has a brightness associated with it. These dots are called picture
An IndustrialTrainingReport on MATLAB 16
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
elements, or more simply pixels.
Image processing
 An image processing refers to processing images by means of various
algorithms.
 A digital image processing refers to the processing of digital images by
means of digital computer.
Formats of Images in MATLAB
 MATLAB can import/export several image formats
 BMP (Microsoft Windows Bitmap)
 GIF (Graphics Interchange Files)
 HDF (Hierarchical Data Format)
 JPEG (Joint Photographic Experts Group)
 PCX (Paintbrush)
 PNG (Portable Network Graphics)
 TIFF (Tagged Image File Format)
 XWD (X Window Dump)
 MATLAB can also load raw-data or other types of image data
Data types in MATLAB
1. Double (64-bit double-precision floating point)
2. Single (32-bit single-precision floating point)
3. Int32 (32-bit signed integer)
4. Int16 (16-bit signed integer)
5. Int8 (8-bit signed integer)
6. Uint32 (32-bit unsigned integer)
An IndustrialTrainingReport on MATLAB 17
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
7. Uint16 (16-bit unsigned integer)
8. Uint8 (8-bit unsigned integer)
IMAGE IN MATLAB
• Binary images : {0,1}
• Intensity images : [0,1] or uint8, double etc.
• RGB images : m-by-n-by-3
• Indexed images : m-by-3 color map
• Multidimensional images m-by-n-by-p (p is the number of layers)
An IndustrialTrainingReport on MATLAB 18
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
Image import and export
 Read and write images in Matlab
>> I=imread('cells.jpg');
>> imshow(I)
>> size(I)
ans = 479 600 3 (RGB image)
>> Igrey=rgb2gray(I);
>> imshow(Igrey)
>> imwrite(lgrey, 'cell_gray.tif', 'tiff')
Alternatives to imshow
>>imagesc(I)
>>imtool(I)
>>image(I)
An IndustrialTrainingReport on MATLAB 19
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
INVERTING AN IMAGE-
To invert or to add two images we need to
convert to double and then rescale the result back so that it looks like an image
InvImg= 1 - double(IMG1)/255;
NewImg = uint8(round(InvImg*255)))
Imshow(NewImg);
An IndustrialTrainingReport on MATLAB 20
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
An IndustrialTrainingReport on MATLAB 21
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
WORKING WITH IMAGE IN MATLAB-
Color Masking
Sometimes we want to replace pixels of an image of one or more colors with
pixels from another image. It is useful to use a “blue or green screen” in some
instances.
Find an image with a big plot of one color. First we will replace that color. And
then we will find another image for pixel replacement. Let us plot the color
values of one chosen row…This will tell us the pixel values of the color we
want to replace.
1. v = imread(‘myimg.jpg’)
2. image(v)
3. row= input(‘which row?’);
4. red = v(row,:,1);
5. green = v(row,:,2);
6. blue = v(row,:,3);
7. plot(red,’r’);
8. hold on
9. plot(green,’g’);
plot(blue,’b’);
Suppose we want to replace those values whose intensities exceed a threshold
value of 160 in each color.
• v= imread(‘myimg.jpg’);
• thresh= 160
• layer = (v(:,:,1) > thresh) & (v(:,:,2) > thresh) (v(:,:,2) > thresh)
• mask(:,:,1) = layer;
• mask(:,:,2) = layer;
• mask(:,:,3) = layer;
If you want to only mask a portion of the image you can use something like…
>> mask(700:end,:,:)= false;
Which sets the mask so that we do not affect rows 700 and above
To reset the color to red
>>newv = v;
>>newv(mask)(1) = 255
An IndustrialTrainingReport on MATLAB 22
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
Or to replace pixels from a different image w use…
>> newv(mask) = w(mask);
Image co-ordinate systems:
Pixel coordinates: In this coordinate system, the image is treated as a grid of
discrete elements, ordered from top to bottom and left to right.
Spatial Coordinates: In this spatial coordinate system, locations in an image
are positions on a plane, and they are described in terms of x and y (not r and
c as in the pixel coordinate system).
Types of Digital Images
 Binary: Each pixel is just black or white. Since there are only two
possible values for each pixel (0,1), we only need one bit per pixel.
 Grayscale: Each pixel is a shade of gray, normally from 0 (black) to 255
(white). This range means that each pixel can be represented by eight
bits, or exactly one byte. Other grey scale ranges are used,but generally
they are a power of 2.
 True Colour, or RGB: Each pixel has a particular color; that color is
described by the amount of red, green and blue in it. If each of these
components has a range 0–255, this gives a total of 2563 different
possible colors. Such an image is a “stack” of three matrices;
representing the red, green and blue values foreach pixel. This means
that for every pixel there correspond 3 values
Image Display and Exploration
1. colorbar:-Display color bar.
2. immovie:-Make movie from multiframe image.
3. implay:-Play movies, videos, or image sequences.
4. imshow:-Display image.
An IndustrialTrainingReport on MATLAB 23
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
5. imtool:-Image Tool.
6. subimage:-Display multiple images in single figure.
Image Types and Type Conversions
1. double:-Convert data to double precision.
2. gray2ind:-Convert grayscale or binary image to indexed image.
3. im2bw:-Convert image to binary image, based on threshold.
4. im2double:-Convert image to double precision.
5. im2int16:-Convert image to 16-bit signed integers.
6. im2single:-Convert image to single precision.
7. im2uint16:-Convert image to 16-bit unsigned integers.
8. im2uint8:-Convert image to 8-bit unsigned integers.
9. ind2gray:-Convert indexed image to grayscale image.
10. ind2rgb:-Convert indexed image to RGB image.
11. mat2gray:-Convert matrix to grayscale image.
12. rgb2gray:-Convert RGB image or colormap to grayscale.
13. rgb2ind:-Convert RGB image to indexed image.
14. uint16:-Convert data to unsigned 16-bit integers.
15. uint8:-Convert data to unsigned 8-bit integers.
Modular Interactive Tools:
1. imageinfo:-Image Information tool.
2. imcontrast:-Adjust Contrast tool.
3. imdisplayrange:-Display Range tool.
4. imdistline:-Distance tool.
5. impixelinfo:-Pixel Information tool.
An IndustrialTrainingReport on MATLAB 24
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
6. impixelregion:-Pixel Region tool.
7. impixelregionpanel:-Pixel Region tool panel.
Image Arithmetic
1. imabsdiff:-Absolute difference of two images.
2. imadd:-Add two images or add constant to image.
3. imcomplement:-Complement image.
4. imdivide:-Divide one image into another or divide image by constant.
5. imlincomb:-Linear combination of images.
6. immultiply:-Multiply two images or multiply image by constant.
7. imsubtract:-Subtract one image from another or subtract constant from
image.
Intensity and Binary Images
1. imbothat:-Bottom-hat filtering.
2. imclearborder:-Suppress light structures connected to image border.
3. imclose:-Morphologically close image.
4. imdilate:-Dilate image.
5. imerode:-Erode image.
6. imfill:-Fill image regions and holes.
7. imopen:-Morphologically open image.
8. imtophat:-Top-hat filtering.
9. strel:-Create morphological structuring element (STREL).
An IndustrialTrainingReport on MATLAB 25
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
Image Enhancement
1. histeq:-Enhance contrast using histogram equalization.
2. imadjust:-Adjust image intensity values or colormap.
Pixel Values and Statistics
1. imcontour:-Create contour plot of image data.
2. imhist:-Display histogram of image data.
3. impixel:-Pixel color values
NOISE IN MATLAB
1. ADDING NOISE
2. FILTERING NOISE
An IndustrialTrainingReport on MATLAB 26
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
MEDIAN FILTER REMOVE GAUSSIAN NOISE
THRESHOLDING
An IndustrialTrainingReport on MATLAB 27
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
GRAPHICAL USER INTERFACE (GUI) :
A graphical user interface
(GUI) is a graphical display that contains devices, or components, that enable a
user to perform interactive tasks. To perform these tasks, the user of the GUI
does not have to create a script or type commands at the command line. Often,
the user does not have to know the details of the task at hand.
The GUI components can be menus, toolbars, push buttons, radio buttons,
list boxes, and sliders—just to name a few. In MATLAB, a GUI can also
display data in tabular form or as plots, and can group related components.
Working of GUI
Each component, and the GUI itself, is associated with one or more user-written
routines known as callbacks. The execution of each callback is triggered by a
particular user action such as a button push, mouse click, selection of a menu
item, or the cursor passing over a component. The creator of the GUI provides
these callbacks. In the GUI, the user selects a data set from the pop-up menu,
then clicks one of the plot type buttons. Clicking the button triggers the
execution of a callback that plots the selected data in the axes. This kind of
programming is often referred to as event-driven programming. The event in the
example is a button click. In event-driven programming, callback execution is
asynchronous, controlled by events external to the software. In the case of
MATLAB GUIs, these events usually take the form of user
interactions with the GUI.
Techniques used to implement the GUI
There are following two techniques to
implement the GUIs in the MATLAB:-
1. Creating a Simple GUI with GUIDE.
2. Creating a Simple GUI Programmatically.
GUIDE: A Brief Introduction:
GUIDE, the MATLAB graphical user interface
development environment, provides a set of tools for creating graphical user
An IndustrialTrainingReport on MATLAB 28
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
interfaces (GUIs). These tools simplify the process of laying out and
programming
GUIs.
The GUIDE Layout Editor enables you to
populate a GUI by clicking and dragging GUI components — such as buttons,
text fields, sliders, axes, and so on— into the layout area. It also enables you to
create menus and context menus
for the GUI.
GUIDE Tools Summary
An IndustrialTrainingReport on MATLAB 29
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
Programming a GUI
When you save your GUI layout, GUIDE automatically generates an
M-file that you can use to control how the GUI works. This M-file provides
code to initialize the GUI and contains a framework for the GUI callbacks—the
routines that execute in response to user-generated events such as a mouse click.
Using the M-file editor, you can add code to the callbacks to perform the
functions you want. Programming a Simple GUI shows you what code to add to
the example Mfile to make the GUI work.
Starting a GUIDE: There are many ways to start GUIDE. We can start
GUIDE from
the:
1. Command line by typing guide
2. Start menu by selecting MATLAB > GUIDE (GUI Builder)
3. MATLAB File menu by selecting New > GUI
4. MATLAB toolbar by clicking the GUIDE button
However we start GUIDE, it displays the GUIDE Quick Start dialog box shown
in the following figure.
An IndustrialTrainingReport on MATLAB 30
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
Blank GUI
The blank GUI template displayed in the Layout Editor is shown in the
following figure.
Creating GUIs Programmatically
1. Callback Execution:-
Callback execution is event driven and callbacks from different GUIs share the
same event queue. In general, callbacks are triggered by user events such as a
mouse click or key press. Because of this, you cannot predict, when a callback
is requested, whether or not another callback is executing or, if one is, which
callback it is.
Various functions used in creating GUIs programmatically are
given below:-
Predefined Dialog Boxes
1. errordlg:- Create and open error dialog box.
2. uigetfile:-Open standard dialog box for retrieving files.
3.uiopen:-Open file selection dialog box with appropriate file filters.
4. uisave:-Open standard dialog box for saving workspace variables.
5.msgbox:-Create and open message box.
An IndustrialTrainingReport on MATLAB 31
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
6. warndlg:-Open warning dialog box.
7.questdlg:-Create and open question dialog box.
8. uiputfile:-Open standard dialog box for saving files.
Deploying User Interfaces
1. guidata:-Store or retrieve GUI data.
2. guihandles:-Create structure of handles.
3. movegui:-Move GUI figure to specified location on screen.
4. openfig:-Open new copy or raise existing copy of saved figure.
User Interface Objects
1. menu:- Generate menu of choices for user input.
2. uibuttongroup:- Create container object to exclusively manage radio
buttons and toggle buttons.
3. uicontextmenu:- Create context menu.
4. uicontrol:- Create user interface control object.
5. uimenu:- Create menus on figure windows.
6. uipanel:- Create panel container object.
7. uipushtool:- Create push button on toolbar.
8. uitoggletool:- Create toggle button on toolbar.
9. uitoolbar:- Create toolbar on figure
An IndustrialTrainingReport on MATLAB 32
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
Adder using GUI :
We have made a simple adder using GUI which can be
deployed and can be used for adding purposes. By using the same GUI we can
adder other functions also like subtract, divide, multiply etc. but we are only
making adder here for learning purpose.
Fig. Final GUI
Steps for making the Adder :
1. Type guide in command prompt:
An IndustrialTrainingReport on MATLAB 33
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
2. This window will appear:
An IndustrialTrainingReport on MATLAB 34
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
3. Select Blank GUI and press ok.
4. 3 edit boxes,1 static box and put it as shown in fig.
An IndustrialTrainingReport on MATLAB 35
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
5. Go on property inspector and change the name.
6. Similarly do it for edit box and push button.
7. For programming part right click the button and press view callback then
write the code in it.
Code:
function input1_editText_Callback(hObject, eventdata, handles)
% hObject handle to input1_editText (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of input1_editText as text
% str2double(get(hObject,'String')) returns contents of
input1_editText as a double
%store the contents of input1_editText as a string. if the string
%is not a number then input will be empty
input = str2num(get(hObject,'String'));
%checks to see if input is empty. if so, default input1_editText to zero
if (isempty(input))
set(hObject,'String','0')
end
An IndustrialTrainingReport on MATLAB 36
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
guidata(hObject, handles);
% --- Executes on button press in add_pushbutton.
function add_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to add_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a = get(handles.input1_editText,'String');
b = get(handles.input2_editText,'String');
% a and b are variables of Strings type, and need to be converted
% to variables of Number type before they can be added together
total = str2num(a) + str2num(b);
c = num2str(total);
% need to convert the answer back into String type to display it
set(handles.answer_staticText,'String',c);
guidata(hObject, handles);
8. Now click the green arrow or click run from the options or either write name
i.e myadder in command window.
9. The below screen will appear, put the values and get the answer.
Here we have put 4 and 20 ad we get 24 as result
An IndustrialTrainingReport on MATLAB 37
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
VOICEBOX: Speech Processing Toolbox for
MATLAB
VOICEBOX is a speech processing toolbox consists of
MATLAB routines that are maintained by and mostly written by Mike Brookes,
Department of Electrical & Electronic Engineering, Imperial College,
Exhibition Road, London SW7 2BT, UK. Several of the routines require
MATLAB V6.5 or above and require (normally slight) modification to work
with earlier versions.
The routine VOICEBOX.M contains various
installation-dependent parameters which may need to be altered before using the
toolbox. In particular it contains a number of default directory paths indicating
where temporary files should be created, where speech data normally resides,
etc. You can override these defaults by editing voicebox.m directly or, more
conveniently, by setting an environment variable VOICEBOX to the path of an
initializing m-file. See the comments in voicebox.m for a fuller description.
MATLAB doesn't really like unicode fonts; some
non-unicode fonts containing IPA phonetic symbols developed by SIL are
available here.
CONTENTS:-
Audio File Input/Output
Read and write WAV and other speech file formats
Frequency Scale
Convert between Hz, Mel, Erb and MIDI frequency scales
Fourier/DCT/Hartley Transforms
Various related transforms
Random Number and Probability Distributions
Generate random vectors and noise signals
An IndustrialTrainingReport on MATLAB 38
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
Vector Distances
Calculate distances between vector lists
Speech Analysis
Active level estimation, Spectrograms
LPC Analysis of Speech
Linear Predictive Coding routines
Speech Synthesis
Text-to-speech synthesis and glottal waveform models
Speech Enhancement
Spectral noise subtraction
Speech Coding
PCM coding, Vector quantisation
Speech Recognition
Front-end processing for recognition
Signal Processing
Miscellaneous signal processing functions
Information Theory
Routines for entropy calculation and symbol codes
Computer Vision
Routines for 3D rotation
Printing and Display Functions
Utilities for printing and graphics
Voicebox Parameters and System Interface
Get or set VOICEBOX and WINDOWS system parameters
Utility Functions
Miscellaneous utility functions
An IndustrialTrainingReport on MATLAB 39
Department of Electronics and Communication Engineering
Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
CONCLUSION
During the training period we have studied that
matlab can be used for variety of applications like computation and
mathematical operations, Algorithm development, Data acquisition, Application
development, including graphical user interface building, building graphs and
plots. process digital images and many more.
REFERENCES
 MATLAB primer R2012a.
 http://www.imc.tue.nl/IMC-main/IMC-main-node8.html#Ch1.6
 http://www.mathworks.in/products/
 http://en.wikipedia.org/wiki/MATLAB

More Related Content

What's hot

What's hot (20)

Matlab practical file
Matlab practical fileMatlab practical file
Matlab practical file
 
Matlab day 1: Introduction to MATLAB
Matlab day 1: Introduction to MATLABMatlab day 1: Introduction to MATLAB
Matlab day 1: Introduction to MATLAB
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processing
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab for Electrical Engineers
Matlab for Electrical EngineersMatlab for Electrical Engineers
Matlab for Electrical Engineers
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
DSP Mat Lab
DSP Mat LabDSP Mat Lab
DSP Mat Lab
 
Basics of MATLAB programming
Basics of MATLAB programmingBasics of MATLAB programming
Basics of MATLAB programming
 
Matlab Overviiew
Matlab OverviiewMatlab Overviiew
Matlab Overviiew
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
What is matlab
What is matlabWhat is matlab
What is matlab
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Fundamentals of matlab
Fundamentals of matlabFundamentals of matlab
Fundamentals of matlab
 

Similar to MATLAB guide

A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsMukesh Kumar
 
matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxlekhacce
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab Arshit Rai
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systemsRaghav Shetty
 
Kevin merchantss
Kevin merchantssKevin merchantss
Kevin merchantssdharmesh69
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTKEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTtejas1235
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introductionAmeen San
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013amanabr
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Kurmendra Singh
 
Introduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdfIntroduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdfDrAzizulHasan1
 

Similar to MATLAB guide (20)

EE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manualEE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manual
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Matlab summary
Matlab summaryMatlab summary
Matlab summary
 
Dsp file
Dsp fileDsp file
Dsp file
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsx
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
 
interfacing matlab with embedded systems
interfacing matlab with embedded systemsinterfacing matlab with embedded systems
interfacing matlab with embedded systems
 
Kevin merchantss
Kevin merchantssKevin merchantss
Kevin merchantss
 
KEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENTKEVIN MERCHANT DOCUMENT
KEVIN MERCHANT DOCUMENT
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 
Matlab tut2
Matlab tut2Matlab tut2
Matlab tut2
 
Matlab
MatlabMatlab
Matlab
 
Matlab basic and image
Matlab basic and imageMatlab basic and image
Matlab basic and image
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
++Matlab 14 sesiones
++Matlab 14 sesiones++Matlab 14 sesiones
++Matlab 14 sesiones
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
 
Introduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdfIntroduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdf
 

Recently uploaded

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 

Recently uploaded (20)

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 

MATLAB guide

  • 1. An IndustrialTrainingReport on MATLAB 1 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA INTRODUCTION TO MATLAB Version-R2008b MATLAB is a high level language for technical computing .It stands for MATrices Laboratory . It is interactive environment for computing, visualizing and programming .It is a purely algorithm based language , scientific , programming based language .With the use of MATLAB we can analyze data, create model and develop algorithm ,Process on signals, in communications, in
  • 2. An IndustrialTrainingReport on MATLAB 2 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA image processing, in speech processing and in control systems we use MATLAB as a tool. Getting started MATLAB is available on department machines. You can also download MATLAB for your personal machine from http://software.caltech.edu. Type “matlab” at the Unix prompt to start. This will open the MATLAB desktop, which includes interactive menus and windows in addition to the command window. You can also start a command prompt-only version of MATLAB (useful if you are logged in remotely) by typing “matlab – nodesktop”. Using MATLAB The best way to learn to use MATLAB is to sit down and try to use it. In this handout are a few examples of basic MATLAB operations, but after you’ve gone through this tutorial you will probably want to learn more. Check out the “Other Resources” listed at the end of this handout. The Beginning When you start MATLAB, the command prompt “>>” appears. You will tell MATLAB what to do by typing commands at the prompt. Creating matrices the basic data element in MATLAB is a matrix. A scalar in MATLAB is a 1x1 matrix, and a vector is a 1xn (or nx1) matrix. For example, create a 3x3 matrix A that has 1’s in the first row, 2’s in the second row, and 3’s in the third row: >> A = [1 1 1; 2 2 2; 3 3 3] The semicolon is used here to separate rows in the matrix. MATLAB gives you: A = 1 1 1 2 2 2 3 3 3 If you don’t want MATLAB to display the result of a command, put a semicolon at the end: >> A = [1 1 1; 2 2 2; 3 3 3]; Matrix A has been created but MATLAB doesn’t display it. The semicolon is necessary when you’re running long scripts and don’t want everything written out to the screen! Suppose you want to access a particular element of matrix A: >> A(1,2) ans = 1
  • 3. An IndustrialTrainingReport on MATLAB 3 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA Suppose you want to access a particular row of A: >> A(2,:) ans = 2 2 2 The “:” operator you have just used generates equally spaced vectors. You can use it to specify a range of values to access in the matrix: >> A(2,1:2) ans = 2 2 You can also use it to create a vector: >> y = 1:3 y = 1 2 3 The default increment is 1, but you can specify the increment to be something else: >> y = 1:2:6 y = 1 3 5 Here, the value of each vector element has been increased by 2, starting from 1, whileless than 6. You can easily concatenate vectors and matrices in MATLAB: >> [y, A(2,:)] ans = 1 3 5 2 2 2 You can also easily delete matrix elements. Suppose you want to delete the 2nd element of the vector y: >> y(2) = [] y = 1 5 MATLAB has several built-in matrices that can be useful. For example, zeros(n,n) makes an nxn matrix of zeros. >> B = zeros(2,2) B = 0 0 0 0 A few other useful matrices are: zeros – create a matrix of zeros ones – create a matrix of ones rand – create a matrix of random numbers
  • 4. An IndustrialTrainingReport on MATLAB 4 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA eye – create an identity matrix Matrix operations An important thing to remember is that since MATLAB is matrix-based, the multiplication operator “*” denotes matrix multiplication. Therefore, A*B is not the same as multiplying each of the elements of A times the elements of B. However, you’ll probably find that at some point you want to do element-wise operations (array operations). In MATLAB you denote an array operator by playing a period in front of the operator. The difference between “*” and “.*” is demonstrated in this example: >> A = [1 1 1; 2 2 2; 3 3 3]; >> B = ones(3,3); >> A*B ans = 3 3 3 6 6 6 9 9 9 >> A.*B ans = 1 1 1 2 2 2 3 3 3 Other than the bit about matrix vs. array multiplication, the basic arithmetic operators in MATLAB work pretty much as you’d expect. You can add (+), subtract (-), multiply (*), divide (/), and raise to some power (^). MATLAB provides many useful functions for working with matrices. It also has many scalar functions that will work element-wise on matrices (e.g., the function sqrt(x) will take the square root of each element of the matrix x). Below is a brief list of useful functions. You’ll find many, many more in the MATLAB help index, and also in the “Other Resources” listed at the end of this handout. Useful matrix functions: A’ – transpose of matrix A. Also transpose(A). det(A) – determinant of A eig(A) – eigenvalues and eigenvectors inv(A) – inverse of A svd(A) – singular value decomposition norm(A) – matrix or vector norm find(A) – find indices of elements that are nonzero. Can also pass an
  • 5. An IndustrialTrainingReport on MATLAB 5 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA expression to this function, e.g. find(A > 1) finds the indices of elements of A greater than 1. A few useful math functions: sqrt(x) – square root sin(x) – sine function. See also cos(x), tan(x), etc. exp(x) – exponential log(x) – natural log log10(x) – common log abs(x) – absolute value mod(x) – modulus factorial(x) – factorial function floor(x) – round down. See also ceil(x), round(x). min(x) – minimum elements of an array. See also max(x). besselj(x) – Bessel functions of first kind MATLAB also has a few built-in constants, such as pi (π) and i (imaginary number). Symbolic math Although MATLAB is primarily used for numerical computations, you can also do symbolic math with MATLAB. Symbolic variables are created using the command “sym.” >> x = sym(‘x’); Here we have created the symbolic variable x. If it seems kind of lame to you to have to type in all this just to create “x”, you’re in luck—MATLAB provides a shortcut. >> syms x This is a shortcut for x = sym(‘x’). Symbolic variables can be used for solving algebraic equations. For example, suppose we want to solve the equation “x^4 + 3*x^2 + 3 = 5”: >> y = solve('x^4 + 3*x^2 + 3 = 5',x) y = -1/2*(-6+2*17^(1/2))^(1/2) 1/2*(-6+2*17^(1/2))^(1/2) -1/2*(-6-2*17^(1/2))^(1/2)
  • 6. An IndustrialTrainingReport on MATLAB 6 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA 1/2*(-6-2*17^(1/2))^(1/2) Since MATLAB is solving for x, a symbolic variable, it writes the answer in symbolic form. That means that the solutions is written out as an expression rather than computed as a decimal value. If you want the decimal value, you need to convert to a double: >> double(y) ans = -0.7494 0.7494 0 - 1.8872i 0 + 1.8872i However, sometimes you may want to see the symbolic expression. In that case, you might want MATLAB to write it out in a way that’s easier to read. For this, use the command “pretty”: >> pretty(y) [ 1/2 1/2] [- 1/2 (-6 + 2 17 ) ] [ ] [ 1/2 1/2 ] [ 1/2 (-6 + 2 17 ) ] [ ] [ 1/2 1/2] [- 1/2 (-6 - 2 17 ) ] [ ] [ 1/2 1/2 ] [ 1/2 (-6 - 2 17 ) ] Below are a few useful things you can do with symbolic variables in MATLAB. For more, look at the “Symbolic Math Toolbox” section of the MATLAB help. solve – symbolic solution of systems of algebraic equations int(f,x) – indefinite integral of f with respect to x int(f,x,a,b) – definite integral of f with respect to x from a to b. diff(f,’x’) – differentiate f with respect to x taylor – Taylor series expansion of symbolic expression
  • 7. An IndustrialTrainingReport on MATLAB 7 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA Features of Matlab  It is easy to learn.  It is an oop (object oriented programming) language.  It has less syntax so less errors.  In Matlab there is no need of declare data types and variable.  It can be use as a programming language.  Errors are interpreted by MATLAB.  We can simulate, model and control with help of Matlab. Different types of windows according to their use are following  Command Windows  Command History  Current Directory  Workspace  Figure Editor  Editor Command Window- Command Window The window where you type commands and non-graphic output is displayed. A ‘>>’ prompt shows you the system is ready for input. The lower left hand corner of the main. window also displays ‘Ready’ or ‘Busy’ when the system is waiting or calculating. Previous commands can be accessed using the up arrow to save typing and reduce errors. Typing a few characters restricts this function to commands beginning with those characters. Workspace- Shows the all the variables that you have currently defined and some basic information about each one, including its dimensions, minimum,
  • 8. An IndustrialTrainingReport on MATLAB 8 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA and maximum values. The icons at the top of the window allow you to perform various basic tasks on variables, creating, saving, deleting, plotting, etc. Double- clicking on a variable opens it in the Variable or Array Editor. All the variables that you’ve defined can be saved from one session to another using File>Save Workspace As (Ctrl-S). The extension for a workspace file is .mat. Command History-Records commands given that session and recent sessions. Can be used for reference or to copy and paste commands. Current directory- The directory (folder) that MATLAB is currently working in. This is where anything you save will go by default, and it will also influence what files MATLAB can see. You won’t be able to run a script that you saved that you saved in a different directory (unless you give the full directory path), but you can run one that’s in a sub-directory. The Current Directory bar at the top centre of the main window lets you change directory in the usual fashion — you can also use the UNIX commands cd and pwd to navigate through directories. The Current Directory window shows a list of all the files in the current directory. Editor-The window where you edit m-files — the files that hold scripts and functions that you’ve defined or are editing — and includes most standard word-processing options and keyboard shortcuts. It can be opened by typing edit in the Command Window. Typing edit myfile will open myfile.m for editing. Multiple files are generally opened as tabs in the same editor window, but they can also be tiled for side by side comparison. Orange warnings and red errors appear as underlining and as bars in the margin. Hovering over them provides more information; clicking on the bar takes you to the relevant bit of text. Also remember that MATLAB runs the last saved version of a file, so you have to save before any changes take effect.
  • 9. An IndustrialTrainingReport on MATLAB 9 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA Figure Editor-MATLAB opens figures in separate windows, which includes the ability to fine-tune the appearance of the plot, zoom, etc. You can also use the Data Cursor to extract values and save them to the Workspace. See the Help documentation for further detail. The figures can also be saved in a wide variety of formats — it’s usually a good idea to save them as an m-file (File>Generate M-file) if there’s any chance at all you might want to modify the figure later and you haven’t already saved the generating code in a m-file. Different types of files in Matlab .m files-when we write program and store in matlab the program is stored in .m extension. M-files and functions If you are doing a computation of any significant length in MATLAB, you will probably want to make an m-file. Anything that you would type at the command
  • 10. An IndustrialTrainingReport on MATLAB 10 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA prompt you can put in the m-file (for example, “script.m”) and then run it all at once (by typing the name of the m-file, e.g. “script”, at the command prompt). You can even add comments to your m-file, by putting a “%” at the beginning of a comment line. You can also use m-files to create your own functions. For example, suppose you want to make a function that increments the value of each element of a matrix by some constant. And suppose you want to call the function “incrementor.” You would make an m-file called “incrementor.m” containing the following: function f = incrementor(x,c) % Incrementor adds c to each element in the matrix x .mat files- MAT-files are double-precision, binary , MATLAB format files. They can also be manipulated by other programs external to MATLAB. .fig files-It is extension of figure or graphical or interface files created in matlab. .asv files –It is auto save file or back up files which are automatically saved along with our original files as a backup. Desktop Tools and Development Environment Command Work exit - Terminates the current MATLAB session. quit -Terminates the current MATLAB session. Clc- Clear Command Window Commandhistory- Open Command History window, or select it if already open. diary -Save session to file. Clear- Removes all variables from the workspace. This frees up system memory. help -Help lists all primary help topics in the Command Window
  • 11. An IndustrialTrainingReport on MATLAB 11 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA exist- Check existence of variable, function, directory, or Java class dir- Directory listing. What- List MATLAB files in current directory. Operations in MATLAB: + Addition + Unary plus - Subtraction - Unary minus * Matrix multiplication ^ Matrix power Backslash or left matrix divides / Slash or right matrix divide ' Transpose .' Nonconjugated transpose .* Array multiplication (element-wise) .^ Array power (element-wise) . Left array divide (element-wise) ./ Right array divide (element-wise)
  • 12. An IndustrialTrainingReport on MATLAB 12 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA Data Analysis commands in MATLAB  mean:- mean (A) returns the mean values of the elements along different dimensions of an array.  median:- returns the median values of the elements along different dimensions of an array.  conv:- conv(u,v) convolves vectors u and v. Algebraically, convolution is the same operation as multiplying the polynomials whose coefficients are the elements of u and v.  convn:- convn(A,B) computes the N-dimensional convolution of the arrays A and B. The size of the result is size(A)+size(B)-1.  deconv:- deconv(v,u) deconvolves vector u out of vector v, using long division. The quotient is returned in vector q and the remainder in vector r such that v = conv(u,q)+r .  poly:- poly(r) where r is a vector returns a row vector whose elements are the coefficients of the polynomial whose roots are the elements of r.  polyval:- polyval(p,x) returns the value of a polynomial of degree n evaluated at x.  polyvalm:- polyvalm(p,X) evaluates a polynomial in a matrix sense. This is the same as substituting matrix X in the polynomial p.  roots:- returns a column vector whose elements are the roots of the polynomial c.  fft:-Discrete Fourier transform.  fft2:-2-D discrete Fourier transform.  fftn:-N-D discrete Fourier transform.
  • 13. An IndustrialTrainingReport on MATLAB 13 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA  ifft:-Inverse discrete Fourier transform.  ifft2:-2-D inverse discrete Fourier transform.  ifftn:-N-D inverse discrete Fourier transform. Graphics commands: plot:- plot(Y) plots the columns of Y versus their index if Y is a real number. plot3:- The plot3 function displays a three-dimensional plot of a set of data points. subplot:- divides the current figure into rectangular panes that are numbered row wise. Each pane contains an axes object. Subsequent plots are output to the current pane. stem: - Plot discrete sequence data. 3-D Visualization Commands:-  surf:- surf(Z) creates a three-dimensional shaded surface from the z components in matrix Z.  mesh:- mesh, meshc, and meshz create wireframe parametric surfaces specified by X, Y, and Z, with color specified by C.  colormap:- A colormap is an m-by-3 matrix of real numbers between 0.0 and Each row is an RGB vector that defines one color.  zoom:-Turn zooming on or off or magnify by factor.  rotate3d:- Rotate 3-D view using mouse.  xlabel, ylabel, zlabel:-Label x-, y-, and z-axis.  contour:-Contour plot of matrix.
  • 14. An IndustrialTrainingReport on MATLAB 14 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA  contour3:- 3-D contour plot.  hist:-Histogram plot.  sphere:-Generate sphere. MATLAB Toolboxes: Toolboxes are collections of functions etc. for tackling particular classes of problems. They have to be purchased separately to use with MATLAB to increase its capabilities. MATLAB contains the following Toolboxes:  SIMULINK Toolbox  Image Processing Toolbox  Control Systems Toolbox  Signal Processing Toolbox  Fuzzy Logic Toolbox  Neural Networks Toolbox  Optimisation Toolbox  Statistics Toolbox  Symbolic maths Toolbox  Mapping Toolbox  Wavelet and many more.
  • 15. An IndustrialTrainingReport on MATLAB 15 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA IMAGE PROCESSING IN MATLAB Image processing toolbox: Image:  An image may defined as a 2-dimensional function, f (x,y), where x & y are spatial (plane) coordinates, & the amplitude of f at any pair of coordinates (x,y) is called the intensity or gray level of the image at that point. When x,y & the amplitude values of f are all finite, discrete quantities, we call the image as Digital image.  A digital image differs from a photo in that the values are all discrete.  A digital image can be considered as a large array of discrete dots, each of which has a brightness associated with it. These dots are called picture
  • 16. An IndustrialTrainingReport on MATLAB 16 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA elements, or more simply pixels. Image processing  An image processing refers to processing images by means of various algorithms.  A digital image processing refers to the processing of digital images by means of digital computer. Formats of Images in MATLAB  MATLAB can import/export several image formats  BMP (Microsoft Windows Bitmap)  GIF (Graphics Interchange Files)  HDF (Hierarchical Data Format)  JPEG (Joint Photographic Experts Group)  PCX (Paintbrush)  PNG (Portable Network Graphics)  TIFF (Tagged Image File Format)  XWD (X Window Dump)  MATLAB can also load raw-data or other types of image data Data types in MATLAB 1. Double (64-bit double-precision floating point) 2. Single (32-bit single-precision floating point) 3. Int32 (32-bit signed integer) 4. Int16 (16-bit signed integer) 5. Int8 (8-bit signed integer) 6. Uint32 (32-bit unsigned integer)
  • 17. An IndustrialTrainingReport on MATLAB 17 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA 7. Uint16 (16-bit unsigned integer) 8. Uint8 (8-bit unsigned integer) IMAGE IN MATLAB • Binary images : {0,1} • Intensity images : [0,1] or uint8, double etc. • RGB images : m-by-n-by-3 • Indexed images : m-by-3 color map • Multidimensional images m-by-n-by-p (p is the number of layers)
  • 18. An IndustrialTrainingReport on MATLAB 18 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA Image import and export  Read and write images in Matlab >> I=imread('cells.jpg'); >> imshow(I) >> size(I) ans = 479 600 3 (RGB image) >> Igrey=rgb2gray(I); >> imshow(Igrey) >> imwrite(lgrey, 'cell_gray.tif', 'tiff') Alternatives to imshow >>imagesc(I) >>imtool(I) >>image(I)
  • 19. An IndustrialTrainingReport on MATLAB 19 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA INVERTING AN IMAGE- To invert or to add two images we need to convert to double and then rescale the result back so that it looks like an image InvImg= 1 - double(IMG1)/255; NewImg = uint8(round(InvImg*255))) Imshow(NewImg);
  • 20. An IndustrialTrainingReport on MATLAB 20 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA
  • 21. An IndustrialTrainingReport on MATLAB 21 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA WORKING WITH IMAGE IN MATLAB- Color Masking Sometimes we want to replace pixels of an image of one or more colors with pixels from another image. It is useful to use a “blue or green screen” in some instances. Find an image with a big plot of one color. First we will replace that color. And then we will find another image for pixel replacement. Let us plot the color values of one chosen row…This will tell us the pixel values of the color we want to replace. 1. v = imread(‘myimg.jpg’) 2. image(v) 3. row= input(‘which row?’); 4. red = v(row,:,1); 5. green = v(row,:,2); 6. blue = v(row,:,3); 7. plot(red,’r’); 8. hold on 9. plot(green,’g’); plot(blue,’b’); Suppose we want to replace those values whose intensities exceed a threshold value of 160 in each color. • v= imread(‘myimg.jpg’); • thresh= 160 • layer = (v(:,:,1) > thresh) & (v(:,:,2) > thresh) (v(:,:,2) > thresh) • mask(:,:,1) = layer; • mask(:,:,2) = layer; • mask(:,:,3) = layer; If you want to only mask a portion of the image you can use something like… >> mask(700:end,:,:)= false; Which sets the mask so that we do not affect rows 700 and above To reset the color to red >>newv = v; >>newv(mask)(1) = 255
  • 22. An IndustrialTrainingReport on MATLAB 22 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA Or to replace pixels from a different image w use… >> newv(mask) = w(mask); Image co-ordinate systems: Pixel coordinates: In this coordinate system, the image is treated as a grid of discrete elements, ordered from top to bottom and left to right. Spatial Coordinates: In this spatial coordinate system, locations in an image are positions on a plane, and they are described in terms of x and y (not r and c as in the pixel coordinate system). Types of Digital Images  Binary: Each pixel is just black or white. Since there are only two possible values for each pixel (0,1), we only need one bit per pixel.  Grayscale: Each pixel is a shade of gray, normally from 0 (black) to 255 (white). This range means that each pixel can be represented by eight bits, or exactly one byte. Other grey scale ranges are used,but generally they are a power of 2.  True Colour, or RGB: Each pixel has a particular color; that color is described by the amount of red, green and blue in it. If each of these components has a range 0–255, this gives a total of 2563 different possible colors. Such an image is a “stack” of three matrices; representing the red, green and blue values foreach pixel. This means that for every pixel there correspond 3 values Image Display and Exploration 1. colorbar:-Display color bar. 2. immovie:-Make movie from multiframe image. 3. implay:-Play movies, videos, or image sequences. 4. imshow:-Display image.
  • 23. An IndustrialTrainingReport on MATLAB 23 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA 5. imtool:-Image Tool. 6. subimage:-Display multiple images in single figure. Image Types and Type Conversions 1. double:-Convert data to double precision. 2. gray2ind:-Convert grayscale or binary image to indexed image. 3. im2bw:-Convert image to binary image, based on threshold. 4. im2double:-Convert image to double precision. 5. im2int16:-Convert image to 16-bit signed integers. 6. im2single:-Convert image to single precision. 7. im2uint16:-Convert image to 16-bit unsigned integers. 8. im2uint8:-Convert image to 8-bit unsigned integers. 9. ind2gray:-Convert indexed image to grayscale image. 10. ind2rgb:-Convert indexed image to RGB image. 11. mat2gray:-Convert matrix to grayscale image. 12. rgb2gray:-Convert RGB image or colormap to grayscale. 13. rgb2ind:-Convert RGB image to indexed image. 14. uint16:-Convert data to unsigned 16-bit integers. 15. uint8:-Convert data to unsigned 8-bit integers. Modular Interactive Tools: 1. imageinfo:-Image Information tool. 2. imcontrast:-Adjust Contrast tool. 3. imdisplayrange:-Display Range tool. 4. imdistline:-Distance tool. 5. impixelinfo:-Pixel Information tool.
  • 24. An IndustrialTrainingReport on MATLAB 24 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA 6. impixelregion:-Pixel Region tool. 7. impixelregionpanel:-Pixel Region tool panel. Image Arithmetic 1. imabsdiff:-Absolute difference of two images. 2. imadd:-Add two images or add constant to image. 3. imcomplement:-Complement image. 4. imdivide:-Divide one image into another or divide image by constant. 5. imlincomb:-Linear combination of images. 6. immultiply:-Multiply two images or multiply image by constant. 7. imsubtract:-Subtract one image from another or subtract constant from image. Intensity and Binary Images 1. imbothat:-Bottom-hat filtering. 2. imclearborder:-Suppress light structures connected to image border. 3. imclose:-Morphologically close image. 4. imdilate:-Dilate image. 5. imerode:-Erode image. 6. imfill:-Fill image regions and holes. 7. imopen:-Morphologically open image. 8. imtophat:-Top-hat filtering. 9. strel:-Create morphological structuring element (STREL).
  • 25. An IndustrialTrainingReport on MATLAB 25 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA Image Enhancement 1. histeq:-Enhance contrast using histogram equalization. 2. imadjust:-Adjust image intensity values or colormap. Pixel Values and Statistics 1. imcontour:-Create contour plot of image data. 2. imhist:-Display histogram of image data. 3. impixel:-Pixel color values NOISE IN MATLAB 1. ADDING NOISE 2. FILTERING NOISE
  • 26. An IndustrialTrainingReport on MATLAB 26 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA MEDIAN FILTER REMOVE GAUSSIAN NOISE THRESHOLDING
  • 27. An IndustrialTrainingReport on MATLAB 27 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA GRAPHICAL USER INTERFACE (GUI) : A graphical user interface (GUI) is a graphical display that contains devices, or components, that enable a user to perform interactive tasks. To perform these tasks, the user of the GUI does not have to create a script or type commands at the command line. Often, the user does not have to know the details of the task at hand. The GUI components can be menus, toolbars, push buttons, radio buttons, list boxes, and sliders—just to name a few. In MATLAB, a GUI can also display data in tabular form or as plots, and can group related components. Working of GUI Each component, and the GUI itself, is associated with one or more user-written routines known as callbacks. The execution of each callback is triggered by a particular user action such as a button push, mouse click, selection of a menu item, or the cursor passing over a component. The creator of the GUI provides these callbacks. In the GUI, the user selects a data set from the pop-up menu, then clicks one of the plot type buttons. Clicking the button triggers the execution of a callback that plots the selected data in the axes. This kind of programming is often referred to as event-driven programming. The event in the example is a button click. In event-driven programming, callback execution is asynchronous, controlled by events external to the software. In the case of MATLAB GUIs, these events usually take the form of user interactions with the GUI. Techniques used to implement the GUI There are following two techniques to implement the GUIs in the MATLAB:- 1. Creating a Simple GUI with GUIDE. 2. Creating a Simple GUI Programmatically. GUIDE: A Brief Introduction: GUIDE, the MATLAB graphical user interface development environment, provides a set of tools for creating graphical user
  • 28. An IndustrialTrainingReport on MATLAB 28 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA interfaces (GUIs). These tools simplify the process of laying out and programming GUIs. The GUIDE Layout Editor enables you to populate a GUI by clicking and dragging GUI components — such as buttons, text fields, sliders, axes, and so on— into the layout area. It also enables you to create menus and context menus for the GUI. GUIDE Tools Summary
  • 29. An IndustrialTrainingReport on MATLAB 29 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA Programming a GUI When you save your GUI layout, GUIDE automatically generates an M-file that you can use to control how the GUI works. This M-file provides code to initialize the GUI and contains a framework for the GUI callbacks—the routines that execute in response to user-generated events such as a mouse click. Using the M-file editor, you can add code to the callbacks to perform the functions you want. Programming a Simple GUI shows you what code to add to the example Mfile to make the GUI work. Starting a GUIDE: There are many ways to start GUIDE. We can start GUIDE from the: 1. Command line by typing guide 2. Start menu by selecting MATLAB > GUIDE (GUI Builder) 3. MATLAB File menu by selecting New > GUI 4. MATLAB toolbar by clicking the GUIDE button However we start GUIDE, it displays the GUIDE Quick Start dialog box shown in the following figure.
  • 30. An IndustrialTrainingReport on MATLAB 30 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA Blank GUI The blank GUI template displayed in the Layout Editor is shown in the following figure. Creating GUIs Programmatically 1. Callback Execution:- Callback execution is event driven and callbacks from different GUIs share the same event queue. In general, callbacks are triggered by user events such as a mouse click or key press. Because of this, you cannot predict, when a callback is requested, whether or not another callback is executing or, if one is, which callback it is. Various functions used in creating GUIs programmatically are given below:- Predefined Dialog Boxes 1. errordlg:- Create and open error dialog box. 2. uigetfile:-Open standard dialog box for retrieving files. 3.uiopen:-Open file selection dialog box with appropriate file filters. 4. uisave:-Open standard dialog box for saving workspace variables. 5.msgbox:-Create and open message box.
  • 31. An IndustrialTrainingReport on MATLAB 31 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA 6. warndlg:-Open warning dialog box. 7.questdlg:-Create and open question dialog box. 8. uiputfile:-Open standard dialog box for saving files. Deploying User Interfaces 1. guidata:-Store or retrieve GUI data. 2. guihandles:-Create structure of handles. 3. movegui:-Move GUI figure to specified location on screen. 4. openfig:-Open new copy or raise existing copy of saved figure. User Interface Objects 1. menu:- Generate menu of choices for user input. 2. uibuttongroup:- Create container object to exclusively manage radio buttons and toggle buttons. 3. uicontextmenu:- Create context menu. 4. uicontrol:- Create user interface control object. 5. uimenu:- Create menus on figure windows. 6. uipanel:- Create panel container object. 7. uipushtool:- Create push button on toolbar. 8. uitoggletool:- Create toggle button on toolbar. 9. uitoolbar:- Create toolbar on figure
  • 32. An IndustrialTrainingReport on MATLAB 32 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA Adder using GUI : We have made a simple adder using GUI which can be deployed and can be used for adding purposes. By using the same GUI we can adder other functions also like subtract, divide, multiply etc. but we are only making adder here for learning purpose. Fig. Final GUI Steps for making the Adder : 1. Type guide in command prompt:
  • 33. An IndustrialTrainingReport on MATLAB 33 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA 2. This window will appear:
  • 34. An IndustrialTrainingReport on MATLAB 34 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA 3. Select Blank GUI and press ok. 4. 3 edit boxes,1 static box and put it as shown in fig.
  • 35. An IndustrialTrainingReport on MATLAB 35 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA 5. Go on property inspector and change the name. 6. Similarly do it for edit box and push button. 7. For programming part right click the button and press view callback then write the code in it. Code: function input1_editText_Callback(hObject, eventdata, handles) % hObject handle to input1_editText (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of input1_editText as text % str2double(get(hObject,'String')) returns contents of input1_editText as a double %store the contents of input1_editText as a string. if the string %is not a number then input will be empty input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','0') end
  • 36. An IndustrialTrainingReport on MATLAB 36 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA guidata(hObject, handles); % --- Executes on button press in add_pushbutton. function add_pushbutton_Callback(hObject, eventdata, handles) % hObject handle to add_pushbutton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a = get(handles.input1_editText,'String'); b = get(handles.input2_editText,'String'); % a and b are variables of Strings type, and need to be converted % to variables of Number type before they can be added together total = str2num(a) + str2num(b); c = num2str(total); % need to convert the answer back into String type to display it set(handles.answer_staticText,'String',c); guidata(hObject, handles); 8. Now click the green arrow or click run from the options or either write name i.e myadder in command window. 9. The below screen will appear, put the values and get the answer. Here we have put 4 and 20 ad we get 24 as result
  • 37. An IndustrialTrainingReport on MATLAB 37 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA VOICEBOX: Speech Processing Toolbox for MATLAB VOICEBOX is a speech processing toolbox consists of MATLAB routines that are maintained by and mostly written by Mike Brookes, Department of Electrical & Electronic Engineering, Imperial College, Exhibition Road, London SW7 2BT, UK. Several of the routines require MATLAB V6.5 or above and require (normally slight) modification to work with earlier versions. The routine VOICEBOX.M contains various installation-dependent parameters which may need to be altered before using the toolbox. In particular it contains a number of default directory paths indicating where temporary files should be created, where speech data normally resides, etc. You can override these defaults by editing voicebox.m directly or, more conveniently, by setting an environment variable VOICEBOX to the path of an initializing m-file. See the comments in voicebox.m for a fuller description. MATLAB doesn't really like unicode fonts; some non-unicode fonts containing IPA phonetic symbols developed by SIL are available here. CONTENTS:- Audio File Input/Output Read and write WAV and other speech file formats Frequency Scale Convert between Hz, Mel, Erb and MIDI frequency scales Fourier/DCT/Hartley Transforms Various related transforms Random Number and Probability Distributions Generate random vectors and noise signals
  • 38. An IndustrialTrainingReport on MATLAB 38 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA Vector Distances Calculate distances between vector lists Speech Analysis Active level estimation, Spectrograms LPC Analysis of Speech Linear Predictive Coding routines Speech Synthesis Text-to-speech synthesis and glottal waveform models Speech Enhancement Spectral noise subtraction Speech Coding PCM coding, Vector quantisation Speech Recognition Front-end processing for recognition Signal Processing Miscellaneous signal processing functions Information Theory Routines for entropy calculation and symbol codes Computer Vision Routines for 3D rotation Printing and Display Functions Utilities for printing and graphics Voicebox Parameters and System Interface Get or set VOICEBOX and WINDOWS system parameters Utility Functions Miscellaneous utility functions
  • 39. An IndustrialTrainingReport on MATLAB 39 Department of Electronics and Communication Engineering Mahakal Institute of Technology, Ujjain- (M.P.) INDIA CONCLUSION During the training period we have studied that matlab can be used for variety of applications like computation and mathematical operations, Algorithm development, Data acquisition, Application development, including graphical user interface building, building graphs and plots. process digital images and many more. REFERENCES  MATLAB primer R2012a.  http://www.imc.tue.nl/IMC-main/IMC-main-node8.html#Ch1.6  http://www.mathworks.in/products/  http://en.wikipedia.org/wiki/MATLAB