Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views29 pages

Lab1 2

This document provides an introduction to MATLAB, highlighting its purpose for numerical computations and data visualizations. It covers the installation process, basic arithmetic operations, variable creation, and the use of matrices and vectors in MATLAB. Additionally, it includes examples and references for further learning about MATLAB functionalities.

Uploaded by

hnjo77
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)
6 views29 pages

Lab1 2

This document provides an introduction to MATLAB, highlighting its purpose for numerical computations and data visualizations. It covers the installation process, basic arithmetic operations, variable creation, and the use of matrices and vectors in MATLAB. Additionally, it includes examples and references for further learning about MATLAB functionalities.

Uploaded by

hnjo77
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/ 29

Faculty of Computer

and Information
Sciences
Information Technology
Department
COMMUNICATIONS AND NETWORKS
FUNDAMENTALS
IT 222T

Lab 1 : Introduction to MATLAB


MATLAB Introduction
• It stands for Matrix Laboratory.
• It was originally designed for solving linear algebra type problems
using matrices
• It is used for numerical computations, data visualizations along with
its programming capabilities.
• It is very useful tool for almost all areas of science and engineering
Why MATLAB ?
• User friendly (GUI)
• Easy to work with
• Powerful tool for complex mathematics
• A comprehensive array of plotting options available from 2 to 4
dimensions.
• A full control of formatting , axes, and other visual representational elements
MATLAB software install
• Go to MATLAB official website
• https://www.mathworks.com/products/matlab.html
• We can download the trial version (30 days)

• Or purchases the student version ($99)


MATLAB software install cont.
MATLAB Interface
Help

Current working directory

Menu bar
Current Command prompt
directory
content

Workspace Command window


(variables MATLAB expressions and statements are
list) evaluated as you type in the command
window and result of the computation are
displayed there too
Using MATLAB as a calculator!!
• MATLAB can work as a calculator
• Basic arithmetic operations which can be used in MATLAB

https://www.mccormick.northwestern.edu/documents/students/undergraduate/introduction-to-matlab.pdf

• Example: Suppose you want to evaluate 1+2 x 3


Using MATLAB as a calculator!! Cont.
• The Precedence of operations

https://www.mccormick.northwestern.edu/documents/students/undergraduate/introduction-to-matlab.pdf

• Let’s consider the previous arithmetic operation, but now we will include
parentheses. For example, 1 + 2 × 3 will become (1 + 2) × 3
NOTE
• You will noticed that if you don’t specify an output variable
MATLAB uses a default variable ans (short for answer) to store the
results of the current calculations.
• Note that the variable ans is overwritten if it is already existed
Creating a MATLAB variable
• MATLAB variables are created with an assignment statement.
• The syntax of variable assignment is
Variable name = a value (or an expression)
• Where expression is a combination of numerical values, mathematical operations ,
variables or function calls
• Example 1: Assign value 5 to a variable named x

• Example 2: Assign expression (1+2*3) to a variable named y


Creating a MATLAB variable cont.
• Example 3: overwriting a variable
• Once a variable has been created , it can be reassigned

• To find out the value of a variable simply type the name


NOTE
• You can suppress the numerical output by putting semicolon ; at the
end of the line (The answer will not be displayed)
• Example: from the previous example if you don’t’ wish to see the
intermediate results , type semicolon ; after the first command
Creating a MATLAB variable cont.
• Example 4: The value of two variables can be added together and stored in
another variable
Creating a MATLAB variable cont.
• Names:
• Can be any string of upper and lower case along with numbers
and underscores but it must begin with a letter
• Reserved names are not allowed to use IF, WHILE, ELSE,
END, SUM, … etc.
• Names are case sensitive
MATLAB Metrices
• Matrices are the basic elements of the MATLAB environment.
• A matrix is a two-dimensional array consisting of m rows and n
columns.
• There are four special cases of metrices in MATLAB:
1. Scalar (m=1, n=1)
2. Column vectors (n = 1)
3. Row vectors (m = 1)
4. Metrices when more than one rows and more than one columns
1.Scalar
• Scalar
• In MATLAB a scalar is a variable with one row and one column.
• Scalars are the simple variables that we use and manipulate in simple
algebraic equations
• Example:
2. Row vectors
• Row vector
• Row vector contains one row and more than one columns
• In MATLAB you can create a row vector using square brackets [ ].
• Elements of the vector may be separated either by one or more blanks or a
comma ,.
• Example1: Create a row vector x with elements
x1 = 1, x2 = -2 and x3 = 5.
2. Row vectors cont.
• Accessing an element
• The elements of a vector are indexed, starting with 1 continuing to the
length of the vector.
• To refer to elements in a vector MATLAB uses round brackets ( ).
• Example: the second element x2 in the previous example , is referenced
by x(2).
• This can be used either to get the value of an element or to assign a value
to an element of a vector.
2.Row vectors cont.
• Accessing several elements of a vector
• MATLAB uses vectors of integers between 1 and the length of a vector to
refer to several elements of a vector at once. For example x([2 3]) refers to
the second and third elements x2, x3 of x. (space or comma can be used to
separate the indices )
• Example: from the previous example For example x([2 3]) refers to the
second and third elements x2, x3 of x.
2.Row vectors cont.
• Number of elements in a vector
• The number of elements in an array (for instance a vector) can be found
using the MATLAB command numel.
• Example: Find the number of elements of the vector x in the previous
exercise.
2.Row vectors cont.
• The colon operator
• Frequently you want to create vectors whose elements are defined by a
simple expression or to access a sequence of elements in a vector. The
colon operator : provides a very convenient way of doing this.
• A slightly more general form of the colon operator is
a:step:b
which starts at a, then adds step repeatedly, until b is reached
• Example: Create a row vector y of the integers between 5 and 11.
2. Row vectors cont.
• Example: Create a row vector y of the integers between 5 and 11 with a step
of 2

• Note: In fact the value of step does not have to be an integer. It can
even be negative, in which case a should be greater than b.
2.Row vectors cont.
• Indexing vectors
• The colon operator is very helpful for indexing
elements of a vector.
• Example: Find the first 3 elements of the
vector y from the previous example

• Note : The MATLAB keyword end is used for


several purposes. When referring to an element
of a vector, it refers to the last element.
• Example: Find the last three elements of the
vector y.
3. Column vectors
• In MATLAB you can also create a column vector using square
brackets [ ].
• However, elements of a column vector are separated either by a
semicolon ; or a newline (what you get when you press the Enter
key)
• Everthing we explained about row vector is also apllied
Note: Transpose
• You can convert a row vector into a column vector (and vice versa)
using the transpose operator ' (an apostrophe).
Book Chapter/ References or Other
materials:
• https://www.maths.unsw.edu.au/sites/default/files/MatlabSelfPaced/lesson3/
MatlabLesson3_ColumnVectors.html
• https://www.mccormick.northwestern.edu/documents/students/undergraduate/
introduction-to-matlab.pdf
• http://math.loyola.edu/~loberbro/matlab/Beginners_guide_to_MATLAB.pdf
• https://web.cecs.pdx.edu/~gerry/MATLAB/variables/scalars.html
THANK YOU

You might also like