Basic Instructions in Mat Lab
Basic Instructions in Mat Lab
1. T = 0: 1:10
This instruction indicates a vector T which has 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
3. T= 0:1/pi: 1
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
0000
6. ones (5,2)
The above instruction creates a vector of five rows and two columns
Output = 11
11
11
11
11
7. a = [ 1 2 3] b = [4 5 6]
a.*b = [4 10 18]
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
Subplot (3 1 2) divides the figure window into 3 rows and 1 column 2 represent number of the
figure
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 that 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
FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points and truncated if it
has more.
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.
ANGLE (H) returns the phase angles, in radians, of a matrix with complex elements.
21. INTERP Resample data at a higher rate using low pass 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) resamples the sequence in vector X at 1/M times the original sample
rate. The resulting resampled vector Y is M times shorter, i.e., LENGTH(Y) = CEIL
(LENGTH(X)/M).