Introduction to MATLAB
MATLAB is
a software package for high performance numerical computation and visualization provides an interactive environment
with hundreds of built in functions for technical computation, graphics and
animation. The MATLAB name stands for MATrix Laboratory
The diagram shows the main
features and capabilities of MATLAB.
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.)
MATLAB Windows:
MATLAB works with through three
basic windows
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
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
Edit
window: This is where you write edit,
create and save your own programs in files
called M 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 write output files
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.
Basic Instructions in Mat lab
1. T = 0: 1:10
This instruction indicates a
vector T which as initial value 0 and final value 10 with an increment of 1
Therefore T = [0 1 2 3 4 5 6 7 8 9 10]
2. F= 20: 1: 100
Therefore F = [20
21 22 23 24 ……… 100]
3. T= 0:1/pi: 1
Therefore T= [0, 0.3183, 0.6366, 0.9549]
4. zeros (1, 3)
The above instruction creates a
vector of one row and three columns whose values are zero
Output= [0 0 0]
5. zeros( 2,4)
|
|
Output =
|
0 0 0 0
|
0 0 0 0
|
6. ones (5,2)
The above instruction creates a vector of five rows
and two columns
Output =
|
1 1
|
1 1
|
|
1 1
|
1 1
1 1
7. a = [ 1
2 3]
b = [4 5
6]
a.*b = [4 10 18]
Which is multiplication of individual elements?
i.e. [4X1 5X2 6X3]
8 if C=
[2 2 2]
b.*C results in [8 10 12]
9. plot (t, x)
If
|
x = [6 7 8 9]
|
t = [1 2 3 4]
|
This instruction will display a figure window which
indicates the plot of x versus t
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
1
(2 2 1) |
2
(2,2,2) |
3
(2 2 3) |
4
(2 2 4) |
Subplot (3, 1, 3)
1 (3,1,1)
|
2 (3,1,2)
|
3 (3,1,3)
|
12. Filter
Syntax: y = filter(b,a,X)
Description:
y = filter(b,a,X) filters the data in vector X with
the filter described by numerator
coefficient vector b and denominator coefficient vector a.If a(1) is not equal
to 1, filter normalizes the filter coefficients by a(1). If a(1) equals 0,
filter returns an error.
13. Impz
Syntax: [h,t] = impz(b,a,n)
Description:
[h,t] = impz(b,a,n) computes the impulse response
of the filter with numerator
coefficients b and denominator coefficients a and computes n samples of the
impulse response when n is an integer (t = [0:n-1]'). If n is a vector of
integers, impz computes the impulse response at those integer locations,
starting the response computation from 0 (and t = n or t = [0 n]). If, instead
of n, you include the empty vector [] for the second argument, the number of
samples is computed automatically by default.
14. Fliplr
Syntax: B = fliplr(A)
Description: B =
fliplr(A) returns A with columns flipped in the left-right direction, that is, about a vertical axis.If A is a
row vector, then fliplr(A) returns a vector of the same length with the order
of its elements reversed. If A is a column vector, then fliplr(A) simply
returns A.
15. 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.
16.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
that disp does not display empty arrays.
17.xlabel
Syntax: xlabel('string')
Description: xlabel('string')
labels the x-axis of the current axes.
18. ylabel
Syntax : ylabel('string')
Description: ylabel('string') labels the y-axis of the current
axes.
19.Title
Syntax : title('string')
Description: title('string') outputs the string at the top and in the center of the current axes.
20.grid on
Syntax : grid on
Description: grid on
adds major grid lines to the current axes.
Procedure to program in MATLAB:
|
1 . Open
Matlab
2. Open
New M-File
3. Type the program
4. Save in current directory
5. Compile and run the program
6. For Output See Command/Figure Window.
|
No comments:
Post a Comment