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

0% found this document useful (0 votes)
13 views104 pages

Lect - 03 - Linear Algebra

The document discusses various topics related to matrices including their definition, characteristics, types, and basic operations. Matrices are defined as rectangular arrangements of numbers organized into rows and columns. The key characteristics discussed are elements, dimensions, and size. Important matrix types covered include vectors, square matrices, triangular matrices, and identity matrices. Basic matrix operations such as addition, subtraction, and multiplication are also introduced.

Uploaded by

jasonmrode
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)
13 views104 pages

Lect - 03 - Linear Algebra

The document discusses various topics related to matrices including their definition, characteristics, types, and basic operations. Matrices are defined as rectangular arrangements of numbers organized into rows and columns. The key characteristics discussed are elements, dimensions, and size. Important matrix types covered include vectors, square matrices, triangular matrices, and identity matrices. Basic matrix operations such as addition, subtraction, and multiplication are also introduced.

Uploaded by

jasonmrode
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/ 104

Machine Learning for Signal Processing

EHB 328E

Ibraheem Shayea
Electronics and Communication Engineering Department,
Faculty of Electrical and Electronics Engineering
İstanbul Teknik Üniversitesi - İTÜ
Syllabus 3

Fundamental of Linear Algebra


Fundamentals of Probability and Statistic

❑ Matrix

❑ Characteristics and Terminology

❑ Types of Matrices

❑ Basic Matrix Operations

❑ Using MATLAB for Matrices


Matrix
Matrix
What is Matrix?

❑ Matrix is a fundamental mathematical and computational concept


used in various fields, including mathematics, physics, engineering,
computer science, and data analysis.

❑ Matrix is a rectangular arrangement of numbers, symbols, or


expressions organized into rows and columns.

❑ Matrices are particularly important in linear algebra and are used to


represent and manipulate data in a structured way.
Matrix
What is a matrix?
Example:

❑ Matrix [A] is denoted by:

 a11 a12 ....... a1n 


a a22 
....... a2 n 
[ A] =  21

   
 
am1 am 2 ....... amn 
Matrix
What is Matrix?
Example:
❑ The matrix below about the sale of tires in a store, given by quarter
and make of tires.
Q1 Q2 Q3 Q4
Tirestone 25 20 3 2 
Michigan  5 10 15 25
 
Copper  6 16 7 27

If one wants to know how many Copper tires were sold in Quarter 4, we
go along the row Copper and column Q4 and find that it is 27.
Matrix
What is Matrix?
Matrices are everywhere

❑ Matrices are everywhere. If you have used a spreadsheet such as


Excel or written a table, you have used a matrix.

❑ Matrices make presentation of numbers clearer and make


calculations easier to program.
Characteristics and Terminology
Characteristics and Terminology
Characteristics and Terminology

❑ Elements

❑ Rows and Columns

❑ Dimensions

❑ Size of Matrix

❑ Scalar

❑ Transpose
Characteristics and Terminology
Elements
❑ The individual entries or values within a matrix are called elements.

❑ Each entry in the matrix is called the entry or element of the matrix.

❑ Elements are typically denoted by lowercase letters and subscripts, aij


where i is the row number and j is the column number of the
element.
Characteristics and Terminology
Rows and Columns
❑ Matrix is a set of elements, organized into rows and columns.

❑ Matrices are organized into rows and columns.

Columns

a b 
Rows
c d 
 
Characteristics and Terminology
Dimensions
❑ Dimensions : The number of rows and columns in a matrix is referred
to as its dimensions.

❑ Matrix with "m" rows and "n" columns is said to have dimensions "m
x n."
Characteristics and Terminology
Size of Matrix
❑ The size of a matrix is determined by its number of rows and
columns.

❑ For example, a "3 x 4" matrix has three rows and four columns.

size of a matrix = m x n
Characteristics and Terminology
Size of Matrix
❑ Each matrix has rows and columns and this defines the size of the
matrix.
o If a matrix [A] has m rows and n columns, the size of the matrix is
denoted by 𝒎 × 𝒏.
o The matrix [A] may also be denoted by [𝐴]𝑚 𝑥 𝑛 to show that [A] is
a matrix with m rows and n columns.
Characteristics and Terminology
Size of Matrix
Example:

❑ The matrix for the tire sales example could be denoted by the matrix
[A] as:

25 20 3 2 
[ A] =  5 10 15 25
a34 =27
 6 16 7 27
❑There are 3 rows and 4 columns, so the size of the matrix is :
size of the matrix = 𝟑 × 𝟒 = 𝟏𝟐.
❑In the above [A] matrix, a34 =27.
Characteristics and Terminology
Scalar

❑ A scalar is a special case of a matrix where it has only one element and
is often represented as a single number.
Characteristics and Terminology
Transpose
❑ The transpose of a matrix is obtained by switching its rows and
columns. If you have a matrix "A," its transpose is denoted as "A^T."
Types of Matrices
Types of Matrices
Special Types of Matrices
❑ Vector
❑ Row Vector
❑ Column Vector
❑ Square Matrix
❑ Submatrix
❑ Upper Triangular Matrix
❑ Lower Triangular Matrix
❑ Diagonal Matrix
❑ Identity Matrix
❑ Zero Matrix
Types of Matrices
What is a Vector?
❑ Vector is a matrix that has only one a 
row or one column.   
❑ Vector is a directed line segment in
v = b 
N-dimensions! (has “length” and
“direction”)  c 
There are two types of vectors: y

❑ Row vectors

❑ Column vectors x
Types of Matrices
Row Vector
❑ Row Vector is a matrix with a single row,

❑ If a matrix [B] has one row, it is called a row vector

[ B] = [b1 b2 bn ]
Where:
n is the dimension of the row vector.
❑Row i of [A] has n elements and is

ai1 ai 2 ....ain 
Types of Matrices
Row Vector

Example

An example of a row vector is as follows:

[ B ] = [25 20 3 2 0]

[B] is an example of a row vector of dimension 5.


Types of Matrices
Column Vector
❑ Column Vector is a matrix with a single column.

❑ If a matrix [C] has one column, it is called a column vector

 c1  Column j of [A] has m



elements and is
[C ] =  
  a1 j 
  a 
c m   2j 
Where:   
m is the dimension of the vector.  
a mj 
Types of Matrices
Column Vector
Example

An example of a column vector is as follows,

25

[C ] =  5 
 6 

[C] is an example of a column vector.


Types of Matrices
Submatrix

If some row(s) or/and column(s) of a matrix [A] are deleted (no


rows or columns may be deleted), the remaining matrix is called a
submatrix of [A].

Example
Submatrices of the matrix
Types of Matrices
Square Matrix

❑ Square Matrix [A] is called a square matrix if the number of


rows m is equal to the number of columns n of a matrix [A],
(m=n).

❑ The entries a11,a22,…, ann are called the diagonal elements of a square
matrix.
❑ Sometimes the diagonal of the matrix is also called the principal or main of
the matrix.
Types of Matrices
Square Matrix
❑ A square matrix has the same number of rows and columns

❑ e.g., "3 x 3" or "2 x 2".


Types of Matrices
Square Matrix
Example of a square matrix.

25 20 3 
[ A] =  5 10 15
 6 15 7 

❑ This is a square matrix as it has the same number of rows and


columns, that is, 3.

❑ The diagonal elements of [A] are : .

a11 = 25, a22 = 10, a33 = 7


Types of Matrices
Upper Triangular Matrix

A m×n matrix for which 𝑎𝑖𝑗 = 0, 𝑖 > 𝑗 is called an upper triangular


matrix. That is, all the elements below the diagonal entries are zero.

Example

Example of an upper triangular matrix.

10 −7 0 
[ A] =  0 − 0.001 6 
 0 0 15005
is an upper triangular matrix.
Types of Matrices
Lower Triangular Matrix

A m×n matrix for which 𝑎𝑖𝑗 = 0, 𝑗 > 𝑖 is called an lower triangular


matrix. That is, all the elements above the diagonal entries are zero.

Example
Give an example of a lower
triangular matrix.
1 0 0
[ A] = 0.3 1 0
0.6 2.5 1

is a lower triangular matrix.


Types of Matrices
Diagonal Matrix

A square matrix with all non-diagonal elements equal to zero is


called a diagonal matrix, that is, only the diagonal entries of the
square matrix can be non-zero, ( aij = 0, i  j )
Types of Matrices
Diagonal Matrix
Example
An example of a diagonal matrix.
3 0 0
[ A] = 0 2.1 0
0 0 0

Any or all the diagonal entries of a diagonal matrix can be zero.

3 0 0
[ A] = 0 0 0
0 0 0
is also a diagonal matrix.
Types of Matrices
Identity Matrix
A diagonal matrix with all diagonal elements equal to one is called an
Identity Matrix

An example of an identity matrix is,

1 0 0 0
0 1 0 0
[ A] = 
0 0 1 0
 
0 0 0 1
Types of Matrices
Zero Matrix

❑ A matrix whose all entries are zero is called a zero matrix,


(aij = 0 for all i and j).

❑ Some examples of zero matrices are:

0 0 0 
0 0 0 
[ A] = 0 0 0 [B] =  
0 0 0 
0 0 0
Operation on Matrices
Operation on Matrices
Basic Matrix Operations

❑ Addition

❑ Subtraction

❑ Scalar Multiplication

❑ Multiplication of Vectors

❑ Multiplication of Matrix and Vector

❑ Multiplication of Matrices

❑ Transpose of a Matrix
Operation on Matrices
Vector Addition

+ w = ( x1 , x2 ) + ( y1 , y2 ) = ( x1 + y1 , x2 + y2 )
vA+B

A
A+B = C
(use the head-to-tail method to
B combine vectors)
C
B

A
Operation on Matrices
Addition of Matrices

❑ Matrices of the same dimensions can be added)

❑ Add the element of the first matrix by the element of the second matrix
in the same position and the answer goes in that same position in the
matrix that is representing the answer.

Just add elements

a b   e f  a + e b + f 
c d  +  g  = 
h  c + g d + h 
  
Operation on Matrices
Addition of Matrices

Example

2 3 4 5 2+4 3+5
+ =
6 7 8 9 6+8 7+9

6 8
=

14 16
Operation on Matrices
Subtracting of Matrices
❑ Matrices of the same dimensions can be subtracted)

❑ Subtract the element of the first matrix by the element of the second
matrix in the same position and the answer goes in that same
position in the matrix that is representing the answer.

Just subtract elements

a b   e f  a − e b − f 
c d  −  g  = 
h  c − g d − h 
  
Operation on Matrices
Subtracting of Matrices

Example
Operation on Matrices
Scalar Multiplication
Scalar Product for vector

av av = a( x1 , x2 ) = (ax1 , ax2 )
av

Change only the length (“scaling”), but keep direction fixed.

Sneak peek: matrix operation (Av) can change length,


direction and also dimensionality!
Operation on Matrices
Scalar Multiplication
❑ Think Distributive Property for Matrices

❑ The element of the matrix are multiplied by a value outside of the


matrix

5 8 23 40 115
=
-11 16 -55 80
Operation on Matrices
Multiplication of Vectors
Vectors: Dot Product

Think of the dot product as a matrix multiplication

𝑑
𝐴⋅𝐵 = 𝑎 𝑏 𝑐 𝑒 = 𝑎𝑑 + 𝑏𝑒 + 𝑐𝑓
𝑓
Operation on Matrices
Multiplication of Matrix and Vector
Matrix Times vector
❑ Matrix is like a function that transforms the vectors on a plane
❑ Matrix operating on a general point => transforms x- and y-
components
❑ System of linear equations: matrix is just the bunch of coeffs !

a b   x   x'
  =  
❑ x’ = ax + by
❑ y’ = cx + dy 
c d   y  y'
Operation on Matrices
Multiplication of Matrix and Vector
Example A= 4 5 8 B= 2
6
9
Now, lets multiply A x B.
1x3 = 3x1

4 5 8 2 = 4 (2) + 5 (6) + 8(9) = 110


6
9
Operation on Matrices
Multiplication of Matrices
❑ In order to multiply two matrices the columns of the first matrix must
be equal to the rows of the second matrix.

[𝐴] × [𝐵]
(𝑚 × 𝑘) (𝑘 × 𝑛)

❑ When doing word problems, make sure the labels of the rows and
columns you are multiplying match as well as the numbers.
Multiply each row by each column

a b   e f  ae + bg af + bh
c d   g  = 
  h  ce + dg cf + dh 
Operation on Matrices
Multiplication of Matrices
❑ If the matrices pass the first test of the columns in the first being equal
to the rows in the second use the following steps to multiply.

A B
2 3 4 5
6 7 8 9

❑ Take the numbers in the first row of matrix A times the numbers in each
of the columns in matrix B.

❑ Then do the same for the numbers in the second row of matrix A times
the numbers in each of the columns in matrix B.
Operation on Matrices
Multiplication of Matrices
Matrix Times Matrix
❑ Let 𝐴 and 𝐵 be matrices whose product, 𝐴 × 𝐵, is defined as 𝐶.

❑ To calculate the value of element 𝑐𝑖,𝑗 , we combine the 𝑖𝑡ℎ row of


matrix 𝐴 and the 𝑗𝑡ℎ column of matrix 𝐵.

❑ A combination of the 2nd row of 𝐴 and the 1st column of 𝐵 gives the
element in the 2nd row and 1st column of 𝐶.
Operation on Matrices
Multiplication of Matrices

Matrix Times Matrix

L = MN

 m11 m12 m13   n11 n12 n13  l11 l12 l13 


m m22 m23   n21 n22 n23  = l21 l22 l23 
 21
 m31 m32 m33   n31 n32 n33  l31 l32 l33 

l12 = m11n12 + m12n22 + m13n32


Operation on Matrices
Exercise
❑ A group of friends are going out for pizza. Given are the ordering
options and the prices for pizza and salad at the two pizza places.

Option 1 Option 2 Vin’s Toni’s


Pizza 4 2 Pizza 11.25 11.95
= [A] = [B]
Salad 6 8 Salad 3.69 2.85

Find the cost of each option at each of the two pizza places?
Operation on Matrices
Transpose of a Matrix
❑ Transpose – ( A T ) of the matrix A is the matrix obtained by
interchanging the rows and columns of matrix A.

1 2 3 1 4
A= AT =
4 5 6 2 5
3 6

The transpose function is in the Matrix catalog, MATH column and the
second choice down.
MATLAB
MATLAB
MATLAB

Review of Linear Algebra


Introduction to Matlab
MATLAB
MATrix LABoratory

❑ Mostly used for mathematical libraries

❑ Very easy to do matrix manipulation in MATLAB

❑ If this is your first time using MATLAB

▪ Strongly suggest you go through the “Getting Started” part of


MATLAB help

▪ Many useful basic syntax


MATLAB Operators and Special Characters
MATLAB Operators and Special Characters

❑ Arithmetic Operators

❑ Relational Operators

❑ Logical Operators

❑ Special Characters

❑ String and Character Formatting


MATLAB Operators and Special Characters
Arithmetic Operators
Symbol Role More Information
+ Addition plus
+ Unary plus uplus
- Subtraction minus
- Unary minus uminus
.* Element-wise multiplication times
* Matrix multiplication mtimes
./ Element-wise right division rdivide
/ Matrix right division mrdivide
.\ Element-wise left division ldivide
\ Matrix left division mldivide
(also known as backslash)
.^ Element-wise power power
^ Matrix power mpower
.' Transpose transpose
' Complex conjugate transpose ctranspose
MATLAB Operators and Special Characters
Relational Operators

Symbol Role More Information

== Equal to eq

~= Not equal to ne

> Greater than gt

>= Greater than or equal to ge

< Less than lt

<= Less than or equal to le


MATLAB Operators and Special Characters
Logical Operators

Symbol Role More Information

& Find logical AND and

| Find logical OR or

&& Find logical AND (with short- Short-Circuit AND


circuiting)
|| Find logical OR (with short- Short-Circuit OR
circuiting)
~ Find logical NOT not
MATLAB Operators and Special Characters
Special Characters
@ Name: At symbol
Uses:
•Function handle construction and reference
•Calling superclass methods
. Name: Period or dot
Uses:
•Decimal point
•Element-wise operations
•Structure field access
•Object property or method specifier
... Name: Dot dot dot or ellipsis
Uses: Line continuation
, Name: Comma
Uses: Separator
MATLAB Operators and Special Characters
Special Characters
: Name: Colon
Uses:
•Vector creation
•Indexing
•For-loop iteration
; Name: Semicolon
Uses:
•Signify end of row
•Suppress output of code line
() Name: Parentheses
Uses:
•Operator precedence
•Function argument enclosure
•Indexing
MATLAB Operators and Special Characters
Special Characters
[] Name: Square brackets
Uses:
•Array construction
•Array concatenation
•Empty matrix and array element deletion
•Multiple output argument assignment
{ } Name: Curly brackets
Uses: Cell array assignment and contents
% Name: Percent
Uses:
•Comment
•Conversion specifier
%{ %} Name: Percent curly bracket
Uses: Block comments
MATLAB Operators and Special Characters
Special Characters

! Name: Exclamation point


Uses: Operating system command
? Name: Question mark
Uses: Metaclass for MATLAB class
'' Name: Single quotes
Uses: Character array constructor
"" Name: Double quotes
Uses: String constructor
N/A Name: Space character
Uses: Separator
N/A Name: Newline character
Uses: Separator
MATLAB Operators and Special Characters
Special Characters
~ Name: Tilde
Uses:
•Logical NOT
•Argument placeholder
= Name: Equal sign
Uses: Assignment
< & Name: Left angle bracket and ampersand
Uses: Specify superclasses
.? Name: Dot question mark
Uses: Specify fields of name-value structure
MATLAB Operators and Special Characters
String and Character Formatting
/ Name: Slash and Backslash
\ Uses: File or folder path separation
Description: In addition to their use as mathematical
operators, the slash and backslash characters separate the
® ®
elements of a path or folder. On Microsoft Windows based
systems, both slash and backslash have the same effect. On
®
The Open Group UNIX based systems, you must use slash
only.
Examples
On a Windows system, you can use either backslash or slash:
dir([matlabroot '\toolbox\matlab\elmat\shiftdim.m'])
dir([matlabroot '/toolbox/matlab/elmat/shiftdim.m'])
On a UNIX system, use only the forward slash:
MATLAB Operators and Special Characters
String and Character Formatting
.. Name: Dot dot
Uses: Parent folder
Description: Two dots in succession refers to the parent of the
current folder. Use this character to specify folder paths relative
to the current folder.
Examples
To go up two levels in the folder tree and down into
the test folder, use:
cd ..\..\test
More Information
•cd
MATLAB Operators and Special Characters
String and Character Formatting
@ Name: At symbol
Uses: Class folder indicator
Description: An @ sign indicates the name of a class folder.
Examples
Refer to a class folder:
\@myClass\get.m
More Information
•Class and Path Folders
MATLAB Operators and Special Characters
String and Character Formatting

+ Name: Plus
Uses: Package directory indicator
Description: A + sign indicates the name of a package folder.
Examples
Package folders always begin with the + character:
+mypack +mypack/pkfcn.m % a package function
+mypack/@myClass % class folder in a package
More Information
•Packages Create Namespaces

https://www.mathworks.com/help/matlab/matlab_prog/matlab-operators-and-special-characters.html#bvg44q6
MATLAB Functions
MATLAB Functions
Functions
size ones clear,
sum length
mean eye clc,
min setdiff inv help …
max ismember diag ….
Find isempty ind2sub
exists intersect
pause sub2ind
exp plot find
sqrt hist logical
sin title repmat
cos, xlabel num2str
reshape
Length ylabel disp
sort legend svd
Sortrows rand eig
var randn sparse
not zeros clear
Matrices
Matrices
Making Arrays
% A simple array
A = [1 2 3 4 5];

B = [1,2,3,4,5];

C = [1;2;3;4;5];

D = A' ;

E = 1:5;

F = 1:2:5;

G = 5:-2:1;

H = rand( 3, 1 );
Matrices
Making Matrices
% All the following are equivalent

L = [1 2 3; 4 5 6; 7 8 9];

M = [1,2,3; 4,5,6; 7,8,9];

N = [[1 2; 4 5; 7 8] [3; 6; 9]];

P = [[1 2 3; 4 5 6]; [7 8 9]];


Matrices
Making Matrices
rows = 5;
cols = 6;
% Creating all zeros Matrix
A = zeros( rows, cols );

% Creating all ones Matrix


B = ones( rows, cols );

% Creating all identity Matrix


C = eye( rows );

% Creating all diagonal Matrix


D = diag([1 2 3]);
Matrices
Making Matrices
% Creating Random matrices
E = rand( rows, cols ); % Unif[0,1]
F = randn( rows, cols); % N(0, 1)

% Make 3x5 with N(1, 4) entries


G = 2 * randn(3,5) + 1;

% Get the size


Size_matrix = size( A );
Matrices
Accessing Elements
Unlike C-like languages, indices start from 1 (NOT 0)

HH = [1 2 3; 4 5 6; 7 8 9];

% Access Individual Elements


HH(2,3);

% Access 2nd column ( : means all elements)


LL = A(:,2);
Matrices
Accessing Elements
A= 123 >> A( A > 5) = -1
456 ans: 1 2 3
789 4 5 -1
Matlab has column-order -1 -1 -1
>> A([1, 3, 5])
ans: 1 7 5 >> A( A > 5) = -1
ans: 7 8 6 9
>> A( [1,3], 2:end )
ans: 2 3
89 >> [i j] = find(A>5)
i= 3 j= 1
3 2
2 3
3 3
Matrices
Matrix Operations
A= 123
456
789
>> A’
>> A + 2 * (A / 4) >> A*A is same as A^2
ans: 1.5000 3.0000 4.5000
6.0000 7.5000 9.0000
10.5000 12.0000 13.5000
>> A.*B
>> A ./ A
ans: 111 >> inv(A)
111
111 >> A/B, A./B, A+B, …
• >> A’
• >> A*A is same as A^2
• >> A.*B
% Solving Systems
• >> inv(A) (A+eye(3)) \ [1;2;3]
• >> A/B, A./B, A+B, … % inv(A+eye(3)) * [1; 2; 3]
• % Solving Systems ans: -1.0000
• (A+eye(3)) \ [1;2;3] -0.0000
• % inv(A+eye(3)) * [1; 2; 3]
• ans: -1.0000
1.0000
• -0.0000
• 1.0000
If … elseif…else…end
If … elseif…else…end
if and elseif
if, elseif, else
Execute statements if condition is true
Syntax

if expression
statements
elseif expression
statements
else
statements
end
If … elseif…else…end
Example 01
nrows = 4;
ncols = 6;
A = ones(nrows,ncols);

for c = 1:ncols
for r = 1:nrows

if r == c
A(r,c) = 2;
elseif abs(r-c) == 1 Output:
A(r,c) = -1;
else A = 4×6
A(r,c) = 0;
end
2 -1 0 0 0 0
end
-1 2 -1 0 0 0
end 0 -1 2 -1 0 0
A 0 0 -1 2 -1 0
If … elseif…else…end
Example 02
clc
clear all
close all

x = 10;
minVal = 2;
maxVal = 6;

if (x >= minVal) && (x <= maxVal)


disp('Value within specified range.')
elseif (x > maxVal)
disp('Value exceeds maximum value.')
else
disp('Value is below minimum value.')
end

Output:
Value exceeds maximum value.
https://www.mathworks.com/help/matlab/ref/if.html
for Statement (loop)
for Statement (loop)
for statement
for
for loop to repeat specified number of times

Syntax

for index = values

statements

end

https://www.mathworks.com/help/matlab/ref/for.html
for Statement (loop)
Example 01

Counter = 0;
for i = 1: 10

if i == 1
Counter(i) = Counter + 2;
else
Counter(i) = Counter (i-1) + 2 .* 2;
end
end

https://www.mathworks.com/help/matlab/ref/for.html
for Statement (loop)
Example 02

s = 10;
H = zeros(s);

for c = 1:s
for r = 1:s
H(r,c) = 1/(r+c-1);
end
end

https://www.mathworks.com/help/matlab/ref/for.html
for Statement (loop)
Example 03

for v = 1.0:-0.2:0.0
disp(v)
end
Output:

1
0.8000
0.6000
0.4000
0.2000
0

https://www.mathworks.com/help/matlab/ref/for.html
for Statement (loop)
Example 04

for v = [1 5 8 17]
disp(v)
end

Output:

17

https://www.mathworks.com/help/matlab/ref/for.html
while
while
Plotting in Matlab
while
while loop to repeat when condition is true
while expression

statements

end
n = 10;
f = n;
while n > 1
n = n-1;
f = f*n;
end
disp(['n! = ' num2str(f)]) n! = 3628800
https://www.mathworks.com/help/matlab/ref/while.html
while
Example 1
fid = fopen('magic.m','r');
count = 0;
while ~feof(fid)
line = fgetl(fid);
if isempty(line) || strncmp(line,'%',1) || ~ischar(line)
continue
end
count = count + 1;
end
count
fileID = fopen(filename) opens the file, filename, for binary read access, and returns an
integer file identifier equal to or greater than 3. MATLAB® reserves file identifiers 0, 1,
and 2 for standard input, standard output (the screen), and standard error, respectively.
https://www.mathworks.com/help/matlab/ref/while.html
while
Example 2

limit = 0.8;
s = 0;

while 1
tmp = rand;
if tmp > limit
break
end
s = s + tmp;
end

https://www.mathworks.com/help/matlab/ref/while.html
while
Example 2

x = 42;
while exist('myfunction.m','file') && (myfunction(x) >= pi)
disp('Expressions are true')
break
end

https://www.mathworks.com/help/matlab/ref/while.html
Plotting in MATLAB
Plotting in MATLAB
Plotting in Matlab

https://www.mathworks.com/products/matlab/plot-gallery.html
Plotting in MATLAB
Plotting in Matlab
%===========================================
% plot
%===========================================
% Lets plot a Gaussian N(0,1)
% Generate 1 million random data points
d = randn(1000000,1);

% Find the histogram


x = min(d):0.1:max(d);
c = histc(d, x);
p = c / 1000000;

% Plot the pdf


plot(x, p);
MATLAB for DataSet
MATLAB for DataSet
Plotting in Matlab
% Parameters
num_samples = 1000; % Number of data points in the dataset
mean_power = -85; % Mean received power (in dBm)
std_deviation = 15; % Standard deviation (in dB)

% Generate synthetic data


received_power = normrnd(mean_power, std_deviation, num_samples, 1);

% Plot the generated data


figure;
histogram(received_power, 20); % Adjust the number of bins as needed
title('Received Signal Power Distribution');
xlabel('Received Signal Power (dBm)');
ylabel('Frequency');

% Save the dataset to a CSV file


data = received_power;
csvwrite('received_power_dataset.csv', data);

% Optional: You can also save the dataset as a MAT file


% save('received_power_dataset.mat', 'received_power');
MATLAB for DataSet
Example 01
MATLAB for DataSet
Plotting in Matlab
% Parameters
num_samples = 1000000; % Number of data points in the dataset
mean_power = -85; % Mean received power (in dBm)
std_deviation = 15; % Standard deviation (in dB)

% Generate synthetic data


received_power = normrnd(mean_power, std_deviation, num_samples, 1);

% Plot the generated data


figure;
histogram(received_power, 20); % Adjust the number of bins as needed
title('Received Signal Power Distribution');
xlabel('Received Signal Power (dBm)');
ylabel('Frequency');

% Save the dataset to a CSV file


data = received_power;
csvwrite('received_power_dataset.csv', data);

% Optional: You can also save the dataset as a MAT file


% save('received_power_dataset.mat', 'received_power');
MATLAB for DataSet
Example 01
Thank You

You might also like