2. MATLAB ASHOK(191890)
PRACTICAL-1
Practical-1: Introduction to MATLAB.
Theory:
. MATLAB is a programming language developed by MathWorks. It started out as a matrix programming language
where linear algebra programming was simple. It can be run both under interactive sessions and as a batch job.
.MATLAB (matrix laboratory) is a fourth-generation high-level programming language and interactive environment
for numerical computation, visualization and programming.
. It allows matrix manipulations; plotting of functions and data; implementation of algorithms; creation of user
interfaces; interfacing with programs written in other languages, including C, C++, Java, and FORTRAN; analyze
data; develop algorithms; and create models and applications.
. It has numerous built-in commands and math functions that help you in mathematical calculations, generating
plots, and performing numerical methods.
Uses of MATLAB:
MATLAB is widely used as a computational tool in science and engineering encompassing the fields of physics,
chemistry, math and all engineering streams. It is used in a range of applications including –
. Signal Processing and Communications
. Image and Video Processing
. Control Systems
. Test and Measurement
. Computational Finance .
Computational Biology
MATLAB Environment:
. Command Window
. Command History
. Workspace .
Current Directory
. Edit Window .
Figure Window
Command Window:
3. MATLAB ASHOK(191890)
Whenever MATLAB is invoked, the main window called command window is activated. The command window
displays the command prompt’>>’ and a cursor where commands are entered and are executed instantaneously.
Command History:
Command history window consists of a list of all the commands that are entered at the command window. These
commands remain in the list until they are deleted. Any command may be executed by selecting and double clicking
it with the mouse.
Workspace:
A workspace is a collection of all the variables that have been generated so far in the current MATLAB session and
shows their data type and size. All the commands executed from Command Window and all the script files executed
from the Command Window share common workspace, so they can share all the variables.
4. MATLAB ASHOK(191890)
Current Directory:
The Current Directory window contains all the files and folders present in the Current Directory. To run any file, it
must either be in the Current Directory or on the search path.
Edit Window:
An Edit Window is used to create a new program file, or to modify existing files. In this window, programs can be
written, edited and saved. The programs written using the MATLAB editor are automatically assigned an extension
(.m) by the editor and are known as M- files.
Figure Window:
A Figure Window is a separate window with default white background and is used to display MATLAB graphics.
The results of all the graphic commands executed are displayed in the figure window.
5. MATLAB ASHOK(191890)
Introduction:
a) Making variables :----------------------
a = 2; it's a number
a = '2'; it's a string
a = [1 2 3 4 5]: it's a vector(array) (in JAVA: int array[] = new int[5])
a = [ 1 2; 3 4] it's a matrix (in JAVA: int array[][] = new int[2][2])
a = {'a',2;'b',3} it's a cell (in JAVA structure)
7. MATLAB ASHOK(191890)
• Magic(): create square matrix n*n
• Transpose():transpose of the matrix
• Flipup():flip the matrix up and down
• Filplr():flip the matrix left to right
8. MATLAB ASHOK(191890)
• Inv(): inverse of the matrix
• a.^2 : square of matrix
• eye() : identity matrix
• rand(): create a matrix from random number
9. MATLAB ASHOK(191890)
C) Basic plot 1) 2-D plot 2) 3-D plot
Syntax
• plot(X,Y)
• plot(X,Y,LineSpec) ---creates the plot using the specified line style, marker, and color.
• plot(X1,Y1,...,Xn,Yn)-- plots multiple pairs of x- and y-coordinates on the same set of axe
11. •
MATLAB ASHOK(191890)
• plot(Y,LineSpec)--- plots Y using implicit x-coordinates, and specifies the line style, marker, and color.
• plot(tbl,xvar,yvar)--- plots the variables xvar and yvar from the table tbl.
• plot(tbl,yvar)--- plots the specified variable from the table against the row indices of the table.
12. •
MATLAB ASHOK(191890)
• plot(ax,___)--- displays the plot in the target axes. Specify the axes as the first argument in any of the previous
syntaxes.
• plot(___,Name,Value)-- specifies Line properties using one or more name-value arguments.