0% found this document useful (0 votes)
45 views

Islamic University of Technology (IUT) : Digital Signals Processing Lab (EEE 4702)

This document provides an overview of 11 useful MATLAB built-in functions: repmat, reshape, linspace, circshift, flip, sort, cumsum, randi, mean, median, and isequal. For each function, it gives a brief description and provides an example to demonstrate how the function works. The document is from a lab manual for a Digital Signal Processing course at the Islamic University of Technology. It aims to introduce some basic MATLAB functions to students.

Uploaded by

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

Islamic University of Technology (IUT) : Digital Signals Processing Lab (EEE 4702)

This document provides an overview of 11 useful MATLAB built-in functions: repmat, reshape, linspace, circshift, flip, sort, cumsum, randi, mean, median, and isequal. For each function, it gives a brief description and provides an example to demonstrate how the function works. The document is from a lab manual for a Digital Signal Processing course at the Islamic University of Technology. It aims to introduce some basic MATLAB functions to students.

Uploaded by

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

ISLAMIC UNIVERSITY OF TECHNOLOGY

(IUT)

Digital Signals Processing Lab (EEE 4702)

Lab-1 (Introduction to MATLAB)

Name: Reduan Ahmed Tanim


Sudent Id: 160021110
Section: B
Group: B2
Department: EEE

Page 1
Some useful matlab built-in function

1. Repmat:
Replicates and tiles an array.

Description:
B = repmat(A,M,N) or B = repmat(A,[M,N]) creates a large matrix B consisting of
an M-by-N tiling of copies of A.
B = repmat(A,N) creates an N-by-N tiling.
B = repmat(A,P1,P2,...,Pn) or B = repmat(A,[P1,P2,...,Pn]) tiles the array A to
produce an n-dimensional array B composed of copies of A.

Example:
In this example, repmat replicates 12 copies of the second-order identity matrix, resulting in a
"checkerboard" pattern.
B = repmat(eye(2),3,4)

B =
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
1 1 0 1 0 1 0 1

2. Reshape:
Reshapes array.

Description:
reshape(X,M,N) or reshape(X,[M,N]) returns the M-by-N matrix whose elements
are taken columnwise from X. An error results if X does not have M*N elements.
reshape(X,M,N,P,...) or reshape(X,[M,N,P,...]) returns an N-D array with the same
elements as X but reshaped to have the size M-by-N-by-P-by-.... The product of
the specified dimensions, M*N*P*..., must be the same as NUMEL(X).

Page 2
Example:
A = 1:10;
B = reshape(A,[5,2])
B = 5×2
1 6
2 7
3 8
4 9
5 10

3. Linspace:
Linearly spaced vector.

Description:
linspace(X1, X2) generates a row vector of 100 linearly equally spaced points
between X1 and X2.
linspace(X1, X2, N) generates N points between X1 and X2.

Example:
y1 = linspace(-5,5,7)
y1 = 1×7
-5.0000 -3.3333 -1.6667 0 1.6667 3.3333
5.0000

4. Circshift:
Shift positions of elements circularly.

Description:
Y = circshift(X,K) where K is an integer scalar circularly shifts the elements in the
array X by K positions. If X is a vector and K is positive, then the values of X are
circularly shifted from the beginning to the end. If K is negative, they are shifted
from the end to the beginning. If X is a matrix, circshift shifts along columns. If X
is an N-D array, circshift shifts along the first nonsingleton dimension.

Page 3
Example:
A = (1:10)
A = 10×1
1
2
3
4
5
6
7
8
9
10
Y = circshift(A,3)
Y = 10×1
8
9
10
1
2
3
4
5
6
7

5. Flip:
Flips the order of elements

Description:
Y = flip(X) returns a vector Y with the same dimensions as X, but with the order of
elements flipped. If X is a matrix, each column is flipped vertically. For N-D
arrays, flip(X) operates on the first nonsingleton dimension.

Page 4
Example:
A = diag([100 200 300])
A = 3×3
100 0 0
0 200 0
0 0 300

B = flip(A)
B = 3×3
0 0 300
0 200 0
100 0 0

6. Sort:
Sorts in ascending or descending order.

Description:
B = sort(A) sorts in ascending order.
The sorted output B has the same type and size as A:
- For vectors, sort(A) sorts the elements of A in ascending order.
- For matrices, sort(A) sorts each column of A in ascending order.
- For N-D arrays, sort(A) sorts along the first non-singleton dimension.

Example:
A = [3 6 5; 7 -2 4; 1 0 -9]
A = 3×3
3 6 5
7 -2 4
1 0 -9

B = sort(A,2)
B = 3×3
3 5 6
-2 4 7
-9 0 1

Page 5
7. Cumsum:
Cumulative sum of elements.

Description:
Y = cumsum(X) computes the cumulative sum along the first non-singleton
dimension of X. Y is the same size as X.

Example:
A = 1:5;
B = cumsum(A)
B = 1×5
2 3 6 10 15

8. Randi:
Pseudorandom integers from a uniform discrete distribution.

Description:
R = randi(IMAX,N) returns an N-by-N matrix containing pseudorandom integer
values drawn from the discrete uniform distribution on 1:IMAX.
randi(IMAX,M,N) or randi(IMAX,[M,N]) returns an M-by-N matrix.
randi(IMAX,M,N,P,...) or randi(IMAX,[M,N,P,...]) returns an M-by-N-by-P-by-...
array.
randi(IMAX) returns a scalar.
randi(IMAX,SIZE(A)) returns an array the same size as A.
R = randi([IMIN,IMAX],...) returns an array containing integer values drawn from
the discrete uniform distribution on IMIN:IMAX.

Example:
r = randi(10,5)
r = 5×5

9 1 2 2 7
10 3 10 5 1
2 6 10 10 9
10 10 5 8 10
7 10 9 10 7

Page 6
9. Mean:
Average or mean value.

Description:
S = mean(X) is the mean value of the elements in X if X is a vector. For matrices,
S is a row vector containing the mean value of each column.
For N-D arrays, S is the mean value of the elements along the first array dimension
whose size does not equal 1.

Example:
A = [0 1 1; 2 3 2; 1 3 2; 4 2 2]
A = 4×3
0 1 1
2 3 2
1 3 2
4 2 2

M = mean(A)
M = 1×3
1.7500 2.2500 1.7500

10. Median:
Median value.

Description:
For vectors, median(x) is the median value of the elements in x.
For matrices, median(X) is a row vector containing the median value of each
column.
For N-D arrays, median(X) is the median value of the elements along the first non-
singleton dimension of X.

Page 7
Example:
A = [0 1 1; 2 3 2; 1 3 2; 4 2 2]
A = 4×3
0 1 1
2 3 2
1 3 2
4 2 2

M = median(A)
M = 1×3
1.5000 2.5000 2.0000

11. Isequal:
True if arrays are numerically equal.

Description:
isequal(A,B) returns logical 1 (TRUE) if arrays A and B are the same size and
contain the same values, and logical 0 (FALSE) otherwise.
If A is defined and you set B = A, isequal(A,B) is not necessarily true.
If A or B contains a NaN element, isequal returns false because NaNs are not equal
to each other by definition.
isequal(A,B,C,...) returns logical 1 if all the input arguments are numerically equal,
and logical 0 otherwise.

Example:
A = zeros(3,3)+1e-20;
B = zeros(3,3);
tf = isequal(A,B)
tf = logical
0

Page 8
Page 9

You might also like