Professional Documents
Culture Documents
Most of the students are worried that they have no access to MATLAB Software. What you can do is,
Option 2: Create a mathworks account on www.mathworks.com, you can download a one-month trial
of MATLAB’s latest version R2020a and start using it.
Option 3: Visit www.mathworks.com on your mobile and create an account by entering valid email
id(can be a business/university/personal ID) and password. Go to download trial version page >> click
on get Started (When a message pops up asking ‘Are you a mobile user?’) >> Enter your contact
information and select your areas of interest (select Wireless Communication as one area of interest).
You’ll receive a mail from mathworks instantly with a link to access MATLAB Online for free and
download MATLAB app. Visit Playstore, download MATLAB Online App, login using your
mathworks account details and start practicing.
Else if you have the MATLAB software already, then you can start practicing directly.
CHAPTER 1
Creating MATLAB Variables
MATLAB variables are created with an assignment statement. The syntax of variable
assignment is, variable name = a value (or an expression)
You can name your MATLAB variables anything you'd like as long as they start with a
letter and contain only letters, numbers, and underscores (_).
MATLAB variables are also case sensitive.
Example Description
a = pi Create variables with the equal sign (=).
The left-side (a) is the variable name containing the value on the right- side
(pi).
b=2 Create variables with the equal sign (=).
The left-side (b) is the variable name containing the value on the right- side
(2).
x = Expression The left-side (x) is the variable name containing any expression. Where an
expression is a combination of numerical values, mathematical operators,
Example: variables, and function calls.
x=log(1) In other words, expression can involve:
x=Sin(2) • manual entry • built-in functions • user-defined functions
THIS DOCUMENT IS PREPARED BY PAVITHRA NAGARAJ (WWW.LINKEDIN.COM/IN/PAVITHRA-NAGARAJ)
MATLAB Learning Series
MATLAB offers many predefined mathematical functions for technical computing which
contains a large set of mathematical functions.
Typing help elfun and help specfun calls up full lists of elementary and special functions
respectively. There is a long list of mathematical functions that are built into MATLAB. These
functions are called built-ins.
>>help elfun
Elementary math functions.
Trigonometric.
sin - Sine.
sind - Sine of argument in degrees.
sinh - Hyperbolic sine.
asin - Inverse sine.
asind - Inverse sine, result in degrees.
asinh - Inverse hyperbolic sine.
cos - Cosine.
cosd - Cosine of argument in degrees.
cosh - Hyperbolic cosine.
Exponential.
exp - Exponential.
expm1 - Compute exp(x)-1 accurately.
log - Natural logarithm.
log1p - Compute log(1+x) accurately.
log10 - Common (base 10) logarithm.
log2 - Base 2 logarithm and dissect floating point number.
pow2 - Base 2 power and scale floating point number.
realpow - Power that will error out on complex result.
reallog - Natural logarithm of real number.
realsqrt - Square root of number greater than or equal to zero.
sqrt - Square root.
nthroot - Real n-th root of real numbers.
nextpow2 - Next higher power of 2.
Complex.
abs - Absolute value.
angle - Phase angle.
complex - Construct complex data from real and imaginary parts.
conj - Complex conjugate.
>>help specfun
Specialized math functions.
Coordinate transforms.
cart2sph - Transform Cartesian to spherical coordinates.
cart2pol - Transform Cartesian to polar coordinates.
pol2cart - Transform polar to Cartesian coordinates.
sph2cart - Transform spherical to Cartesian coordinates.
hsv2rgb - Convert hue-saturation-value colors to red-green-blue.
rgb2hsv - Convert red-green-blue colors to hue-saturation-value.
Overwriting Variables
Once a variable has been created, it can be reassigned.
In addition, if you do not wish to see the intermediate results, you can suppress the numerical
output by putting a semicolon (;) at the end of the line. Then the sequence of commands looks
like this:
CHAPTER 2
Array Generation and Operations
Array types
Example Description
A=4 scalar
A = [3 5] row vector
A = [1;3] column vector
A = [3 4 5;6 7 8] matrix
>>A = 4
A=
4
>>A = [3 10 12]
A=
3 10 12
>>A = [1;5;3]
A=
1
5
3
>>A = [1 2;3 4]
A=
1 2
3 4
Example Description
1:4 Create a vector from 1 to 4, spaced by 1, using the
colon (:) operator.
1:0.5:4 Create a vector from 1 to 4, spaced by 0.5.
linspace(1,10,5) Create a vector with 5 elements. The values are evenly
spaced from 1 to 10.
Matrix Generation
Example Description
A=[1 2;3 4] Create a square matrix with 2 rows and 2 columns. The elements of
the first row are 1 and 2, the elements of second row are 3 and 4.
A=[1 2 3;4 5 6;7 8 Create a square matrix with 3 rows and 3 columns. The elements of
9] the first row are 1, 2 and 3, the elements of second row are 4,5 and 6
and the elements of third row are 7,8 and 9.
rand(2) Create a square matrix with 2 rows and 2 columns. The matrix
elements will be randomly generated.
zeros(2,3) Create a rectangular matrix with 2 rows and 3 columns. All the
matrix elements will be Zero.
ones(2,3) Create a rectangular matrix with 2 rows and 3 columns. All the
matrix elements will be One.
eye(3) Create an Identity matrix with 3 rows and 3 columns. A Identity
Matrix with ones as diagonal elements and zeros as elements in
upper and lower triangular matrices is generated.
[xrow,xcol] = size(x) Save the number of rows and columns in x to two different
variables.
[xMax,idx] = max(x) Calculate the maximum value of x and its corresponding index
value.
A(i,j) Accessing the elements in a MxN matrix A. I ranges between to 1 to
M(No.of Rows) and j ranges between 1 to N(No.of Columns).
Matrix Multiplication:
Matrix Division:
>>A*B’
>>A’*B
>>D = D’
8
2
3