0% found this document useful (0 votes)
15 views8 pages

exp-0 CS

Hh

Uploaded by

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

exp-0 CS

Hh

Uploaded by

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

INTRODUCTION TO MATLAB

MATLAB (Matrix Laboratory):

MATLAB is a software package for high-performance language for technical computing.


It integrates computation, visualization, and PROGRAMming in an easy-to-use
environment where problems and solutions are expressed in familiar mathematical
notation. Typical uses include the following:

Math and computation


Algorithm development
Data acquisition
Modeling, simulation, and prototyping
Data analysis, exploration, and visualization
Scientific and engineering graphics
Application development, including graphical user interface building

11 | P a g e
At its core ,MATLAB is essentially a set (a “toolbox”) of routines (called “m files” or “mex
files”) that sit on your computer and a window that allows you to create new variables
with names (e.g. voltage and time) and process those variables with any of those
routines (e.g. plot voltage against time, find the largest voltage, etc).

It also allows you to put a list of your processing requests together in a file and
save that combined list with a name so that you can run all of those commands in the
same order at some later time. Furthermore, it allows you to run such lists of commands
such that you pass in data and/or get data back out (i.e. the list of commands is like a
function in most programming languages). Once you save a function, it becomes part of
your toolbox (i.e. it now looks to you as if it were part of the basic toolbox that you
started with). For those with computer programming backgrounds: Note that MATLAB
runs as an interpretive language (like the old BASIC). That is, it does not need to be
compiled. It simply reads through each line of the function, executes it, and then goes
on to the next line. (In practice, a form of compilation occurs when you first run a
function, so that it can run faster the next time you run it.)

The name MATLAB stands for matrix laboratory. MATLAB was originally written to
provide easy access to matrix software developed by the LINPACK and EISPACK projects.
Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the
state of the art in software for matrix computation. MATLAB has evolved over a period
of years with input from many users. In university environments, it is the standard
instructional tool for introductory and advanced courses in mathematics, engineering,
and science. In industry, MATLAB is the tool of choice for high-productivity research,
development, and analysis.

MATLAB features a family of add-on application-specific solutions called toolboxes. Very


important to most users of MATLAB, toolboxes allow learning and applying specialized
technology. Toolboxes are comprehensive collections of MATLAB functions (M-files)
that extend the MATLAB environment to solve particular classes of problems. Areas in
which toolboxes are available include Image processing, signal processing, control
systems, neural networks, fuzzy logic, wavelets, simulation, and many others.

12 | P a g e
The main features of MATLAB

1. Advance algorithm for high performance numerical computation, especially in the Field matrix
Algebra.
2. A large collection of predefined mathematical functions and the ability to define one’s own
functions.
3. Two-and three dimensional graphics for plotting and displaying data.
4. A complete online help system.

5. Powerful, matrix or vector oriented high level programming language for individual
applications.

6. Toolboxes available for solving advanced problems in several application areas.

MATLAB Windows: MATLAB works through three basic windows

1.Command Window : This is the main window .It is characterized by MATLAB command
prompt >> when you launch the application PROGRAM MATLAB puts you in this window all
commands including those for user-written PROGRAMs ,are typed in this window at the MATLAB
prompt .
2.Graphics window: the OUTPUT of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background color
the user can create as many windows as the system memory will allow .
3. Edit window: This is where you write, edit, create and save your own PROGRAMs in files
called M files.

Write OUTPUT files. Input-OUTPUT: MATLAB supports interactive computation taking


the input from the screen and flushing, the OUTPUT to the screen. In addition it can
read input files and

13 | P a g e
Data Type: the fundamental data–type in MATLAB is the array. It encompasses several
distinct data objects- integers, real numbers, matrices, character strings, structures and
cells. There is no need to declare variables as real or complex, MATLAB automatically
sets the variable to be real.

Dimensioning: Dimensioning is automatic in MATLAB. No dimension statements are


required for vectors or arrays .we can find the dimensions of an existing matrix or a
vector with the size and length commands.

The functional unit of data in any MATLAB PROGRAM is the array. An array is a collection of
data values organized into rows and columns, and known by a single name.

MATLAB variable is a region of memory containing an array, which is known by a user specified
name. MATLAB variable names must begin with a letter, followed by any combination of letters,
numbers, and the underscore (_) character. Only the first 31 characters are significant; if more
than 31 are used, the remaining characters will be ignored. If two variables are declared with
names that only differ in the 32nd character, MATLAB will treat them as same variable.
Spaces cannot be used in MATLAB variable names, underscore letters can be substituted to
create meaningful names.
It is important to include a data dictionary in the header of any PROGRAM that you write. A
data dictionary lists the definition of each variable used in a PROGRAM. The definition should
include both a description of the contents of the item and the units in which it is measured.

MATLAB language is case-sensitive. It is customary to use lower-case letters for


ordinary variable names.

The most common types of MATLAB variables are double and char.

MATLAB is weakly typed language. Variables are not declared in a PROGRAM before it is used.
MATLAB variables are created automatically when they are initialized. There are three

Common ways to initialize variables in MATLAB:


Assign data to the variable in an assignment system.
Input data into the variable from the keyboard.
Read data from a file.

14 | P a g e
The semicolon at the end of each assignment statement suppresses the automatic
echoing of values that normally occurs whenever an expression is evaluated in an
assignment statement.

How to invoke MATLAB?


Double Click on the MATLAB icon on the desktop.
You will find a Command window where in which you can type the commands and see the
OUTPUT. For example if you type PWD in the command window, it will print current working
directory.
If you want to create a directory type mkdir mydir in the command window, it will create a
directory called pes.
If you want delete a directory type rmdir mydir in the command window.
How to open a file in MATLAB?
Go to File _ New_ M-File and click
Then type the PROGRAM in the file and save the file with an extension of .m. While giving
filename we should make sure that given file name should not be a command. It is better
to give the filename as myconvolution .
How to run a MATLAB file?
Go to Debug->run and click

Where to work in MATLAB?


All PROGRAMs and commands can be entered either in the a) Command window b) As an M file
using MATLAB editor
Note: Save all M files in the folder 'work' in the current directory. Otherwise you have to locate
the file during compiling. Typing quit in the command prompt >> quit, will close MATLAB
Development Environment. For any clarification regarding plot etc, which are built in functions
type help topic
I.e. help plot

15 | P a g e
Basic Instructions in MATLAB:

10. stem (t,x) :- This instruction will display a figure window as shown

11. Subplot: This function divides the figure window into rows and columns. Subplot (2 2 1)
divides the figure window into 2 rows and 2 columns 1 represent number of the
figure

16 | P a g e
Subplot (3 1 2) divides the figure window into 3 rows and 1 column 2 represent the
figure number
12. Conv Syntax: w = conv(u,v) Description: w = 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.

13. Disp Syntax: disp(X) Description: disp(X) displays an array, without printing the array name. If
X contains a text string, the string is displayed. Another way to display an array on the screen is
to type its name, but this prints a leading "X=," which is not always desirable.
Note: disp does not display empty arrays.

14. xlabel Syntax: xlabel('string')


Description: xlabel('string') labels the x-axis of the current axes.

15. ylabel Syntax : ylabel('string')


Description: ylabel('string') labels the y-axis of the current axes.

16. Title Syntax : title('string') Description: title('string') OUTPUTs the string at the top and in the
center of the current axes.

17. grid on Syntax : grid on Description: grid on adds major grid lines to the current axes.

17 | P a g e
18. FFT Discrete Fourier transform. FFT(X) is the discrete Fourier transform (DFT) of vector X. For
matrices, the FFT operation is applied to each column. For N-D arrays, the FFT operation operates on the
first non-singleton dimension. FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points
and truncated if it has more.

19. ABS Absolute value. ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is
the complex modulus (magnitude) of the elements of X.

20. ANGLE Phase angle. ANGLE (H) returns the phase angles, in radians, of a matrix with complex
elements.

21. INTERP Resample data at a higher rate using lowpass interpolation. Y = INTERP(X,L) resamples the
sequence in vector X at L times the original sample rate. The resulting resampled vector Y is L times
longer, LENGTH(Y) = L*LENGTH(X).

22. DECIMATE Resample data at a lower rate after low pass filtering.
Y = DECIMATE(X, M) resample the sequence in vector X at 1/M times the original
sample rate. The resulting resample vector Y is M times shorter, i.e., LENGTH(Y) = CEIL
(LENGTH(X)/M). By default, DECIMATE filters the data with an 8th order Chebyshev Type I low
pass filter with cutoff frequency .8*(Fs/2)/R, before resampling.

18 | P a g e

You might also like