SlideShare a Scribd company logo
MATLAB
Syed Khalid Ahmed
 MATLAB (Matrix Laboratory) [1]
 MATLAB(matrix laboratory) is a multi-paradigm
numerical computing environment and fourth-generation
programming language.
 Developed by Math Works, MATLAB allows matrix
manipulations, plotting of functions and data,
implementation of algorithms, creation of user interfaces,
and interfacing with programs written in other
languages, including C, C++, Java and Fortran.
MATLAB
 MATLAB (Matrix Laboratory) [2]
 Although MATLAB is intended primarily for numerical
computing, an option al toolbox uses the MuPAD
symbolic engine, allowing access to symbolic computing
capabilities. An additional package, Simulink, adds
graphical multi-domain simulation and Model-Based
Design for dynamic and embedded systems.
 In 2004, MATLAB had around one million users across
industry and academia. MATLAB users come from
various backgrounds of engineering, science, and
economics. MATLAB is widely used in academic and
research institutions as well as industrial enterprises.
MATLAB
 Commands
 >>433.12*15.7
 ans=6.8000e+003
 MATLAB spits out the answer to our query conveniently
named ans.
 This is a variable or symbolic name that can be used to
represent the value later.
 >>x=5*6
 X=30
MATLAB
 Commands
 To write the multiplication ab, in MATLAB we type a*b
 For division, the quantity a÷b is typed as a/b. This type
of division is referred to as right division.
 MATLAB also allows another way to enter division,
called left division. We can enter the quantity by a
typing the slash mark used for division in the opposite
way, that is, we use a back slash instead of a forward
slash ab
MATLAB
 Commands
 Exponentiation a to the power b is entered in the
following way a ^ b
 Finally, addition and subtraction are entered in the
usual way
 a + b
 a –b
MATLAB
 Commands
 Individual matrix and vector entries can be referenced
with indices inside parentheses. For example, A(2,3)
denotes the entry in the second row, third column of
matrix A.
 A=[123;456;-179]
 A(2,3)
 Create a column vector, x, with:
 x=[321]’
 Or equivalently:
 x=[3;2;1]
MATLAB
 Commands
 The relational operators in MATLAB are:
 < less than
 > greater than
 <= less than or equal
 >= greater than or equal
 == equal
 ~= not equal
 Note that = is used in an assignment statement whereas
== is a relational operator.
MATLAB
 Commands
 Logical operators:
 Relational operators may be connected by logical
operators:
 & and
 | or
 ~ not
 && short-circuit and
 || short-circuit or
MATLAB
 Commands
 Inner product or dot product
 .* Array multiply:
 X.*Y denotes element-by-element multiplication. X and
Y must have the same dimensions unless one is a
scalar.
 * Matrix multiply:
 X*Y is the matrix product of X and Y. Any scalar (a 1-by-
1 matrix) may multiply anything. Otherwise, the number
of columns of X must equal the number of rows of Y.
MATLAB
 Commands
 /Slash or right matrix divide:
 A/B is the matrix division of B into A, which is roughly the
same as A*INV(B), except it is computed in a different
way. More precisely, A/B = (B'A')'.
 Backslash or left matrix divide:
 AB is the matrix division of A into B, which is roughly the
same as INV(A)*B, except it is computed in a different
way. If A is an N-by-N matrix and B is a column vector
with N components, or a matrix with several such
columns, then X=AB is the solution to the equation
singular
MATLAB
 Commands
 To divide Matrices, element-by-element, the following
formula is useful A./B
 A = [2 4 6 8]; B = [2 2 3 1];
 C = A./B
 % C = [1 2 2 8]
 Array left division is indicated by writing C = A.B (this
is the same as C = B./A):
 C = A.B
 % C = [1.0000 0.5000 0.5000 0.125]
MATLAB
 Commands
 fix()
 fix(X) rounds the elements of X to the nearest integers
towards zero.
 >> fix(5.5)
 ans =
 5
 >> fix(5.9)
 ans =
 5
MATLAB
 Commands
 rand()
 rand():returns an n-by-n matrix containing pseudo
random values drawn from the standard uniform
distribution on the open interval(0,1).
 >> n = rand(1,10)
 n =0.1576 0.9706 0.9572 0.4854 0.8003 0.1419
0.4218 0.9157 0.7922 0.9595
 >> n = fix(10*rand(1,10))
 n =8 9 1 9 6 0 2 5 9 9
MATLAB
 Commands
 Question: Simulate the outcomes of 1000 biased coin
tosses with p[Head] = 0.3
 Solution:
 n = 1000;
 randomNumber= rand(n,1);
 Heads = randomNumber<= 0.3;
 totalNumberOfHeads= sum(Heads);
 probabilityOfHeads= totalNumberOfHeads/n;
MATLAB
 Commands
 Plot(x,y) plot the graph between x and y.
 X and y are the vectors of same lengths.
 >>X=1:10
 >>y=11:20
 >> plot(x,y)
MATLAB
 Commands
 Two or more than two graphs plot on at same time with
hold on function
 x=-5:5
 y=x.*x
 plot(x,y)
 hold on
 a=1:5
 b=1:5
 plot(a,b)
MATLAB
K-MEANS
CLUSTERING
INTRODUCTION-
What is clustering?
 Clustering is the classification of objects into
different groups, or more precisely, the
partitioning of a data set into subsets
(clusters), so that the data in each subset
(ideally) share some common trait - often
according to some defined distance measure.
Common Distance measures:
 Distance measure will determine how the similarity of two
elements is calculated and it will influence the shape of the
clusters.
They include:
1. The Euclidean distance (also called 2-norm distance) is
given by:
2. The Manhattan distance (also called taxicab norm or 1-
norm) is given by:
K-MEANS CLUSTERING
 The k-means algorithm is an algorithm to cluster
n objects based on attributes into k partitions,
where k < n.
K-MEANS CLUSTERING
 Simply speaking k-means clustering is an
algorithm to classify or to group the objects
based on attributes/features into K number of
group.
 K is positive integer number.
 The grouping is done by minimizing the sum
of squares of distances between data and the
corresponding cluster centroid.
How the K-Mean Clustering
algorithm works?
 Step 1: Begin with a decision on the value of k =
number of clusters .
 Step 2: Put any initial partition that classifies the
data into k clusters. You may assign the
training samples randomly,or systematically
as the following:
1.Take the first k training sample as single-
element clusters
2. Assign each of the remaining (N-k) training
sample to the cluster with the nearest
centroid. After each assignment, recompute the
centroid of the gaining cluster.
 Step 3: Take each sample in sequence and
compute its distance from the centroid of
each of the clusters. If a sample is not
currently in the cluster with the closest
centroid, switch this sample to that cluster
and update the centroid of the cluster
gaining the new sample and the cluster
losing the sample.
 Step 4 . Repeat step 3 until convergence is
achieved, that is until a pass through the
training sample causes no new assignments.
Applications of K-Mean
Clustering
 It is relatively efficient and fast. It computes result
at O(tkn), where n is number of objects or points, k
is number of clusters and t is number of iterations.
 k-means clustering can be applied to machine
learning or data mining
 Used on acoustic data in speech understanding to
convert waveforms into one of k categories (known
as Vector Quantization or Image Segmentation).
 Also used for choosing color palettes on old
fashioned graphical display devices and Image
Quantization.
K-Mean Image Processing
Demo
Intro to MATLAB and K-mean algorithm
Intro to MATLAB and K-mean algorithm
Ad

Recommended

Enhance The K Means Algorithm On Spatial Dataset
Enhance The K Means Algorithm On Spatial Dataset
AlaaZ
 
K-means Clustering
K-means Clustering
Sajib Sen
 
K MEANS CLUSTERING
K MEANS CLUSTERING
singh7599
 
K mean-clustering
K mean-clustering
Afzaal Subhani
 
K means
K means
Tien-Yang (Aiden) Wu
 
Neural nw k means
Neural nw k means
Eng. Dr. Dennis N. Mwighusa
 
K means clustering
K means clustering
Thomas K T
 
K means clustering | K Means ++
K means clustering | K Means ++
sabbirantor
 
K-means Clustering Algorithm with Matlab Source code
K-means Clustering Algorithm with Matlab Source code
gokulprasath06
 
K means clustering
K means clustering
Ahmedasbasb
 
K-Means manual work
K-Means manual work
Dr.E.N.Sathishkumar
 
CC282 Unsupervised Learning (Clustering) Lecture 7 slides for ...
CC282 Unsupervised Learning (Clustering) Lecture 7 slides for ...
butest
 
K-means clustering algorithm
K-means clustering algorithm
Vinit Dantkale
 
K means
K means
Elias Hasnat
 
K mean-clustering algorithm
K mean-clustering algorithm
parry prabhu
 
Cluster analysis using k-means method in R
Cluster analysis using k-means method in R
Vladimir Bakhrushin
 
K Means Clustering Algorithm | K Means Example in Python | Machine Learning A...
K Means Clustering Algorithm | K Means Example in Python | Machine Learning A...
Edureka!
 
Data miningpresentation
Data miningpresentation
Manoj Krishna Yadavalli
 
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
Simplilearn
 
K means clustring @jax
K means clustring @jax
Yaduvanshi Yadav
 
Kmeans
Kmeans
Nikita Goyal
 
Customer Segmentation using Clustering
Customer Segmentation using Clustering
Dessy Amirudin
 
K means clustering algorithm
K means clustering algorithm
Darshak Mehta
 
An improvement in k mean clustering algorithm using better time and accuracy
An improvement in k mean clustering algorithm using better time and accuracy
ijpla
 
K means clustering
K means clustering
keshav goyal
 
K mean-clustering
K mean-clustering
PVP College
 
08 clustering
08 clustering
นนทวัฒน์ บุญบา
 
Rough K Means - Numerical Example
Rough K Means - Numerical Example
Dr.E.N.Sathishkumar
 
Cardiac Image Analysis based on K Means Clustering
Cardiac Image Analysis based on K Means Clustering
NAVEEN TOKAS
 
K means and dbscan
K means and dbscan
Yan Xu
 

More Related Content

What's hot (20)

K-means Clustering Algorithm with Matlab Source code
K-means Clustering Algorithm with Matlab Source code
gokulprasath06
 
K means clustering
K means clustering
Ahmedasbasb
 
K-Means manual work
K-Means manual work
Dr.E.N.Sathishkumar
 
CC282 Unsupervised Learning (Clustering) Lecture 7 slides for ...
CC282 Unsupervised Learning (Clustering) Lecture 7 slides for ...
butest
 
K-means clustering algorithm
K-means clustering algorithm
Vinit Dantkale
 
K means
K means
Elias Hasnat
 
K mean-clustering algorithm
K mean-clustering algorithm
parry prabhu
 
Cluster analysis using k-means method in R
Cluster analysis using k-means method in R
Vladimir Bakhrushin
 
K Means Clustering Algorithm | K Means Example in Python | Machine Learning A...
K Means Clustering Algorithm | K Means Example in Python | Machine Learning A...
Edureka!
 
Data miningpresentation
Data miningpresentation
Manoj Krishna Yadavalli
 
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
Simplilearn
 
K means clustring @jax
K means clustring @jax
Yaduvanshi Yadav
 
Kmeans
Kmeans
Nikita Goyal
 
Customer Segmentation using Clustering
Customer Segmentation using Clustering
Dessy Amirudin
 
K means clustering algorithm
K means clustering algorithm
Darshak Mehta
 
An improvement in k mean clustering algorithm using better time and accuracy
An improvement in k mean clustering algorithm using better time and accuracy
ijpla
 
K means clustering
K means clustering
keshav goyal
 
K mean-clustering
K mean-clustering
PVP College
 
08 clustering
08 clustering
นนทวัฒน์ บุญบา
 
Rough K Means - Numerical Example
Rough K Means - Numerical Example
Dr.E.N.Sathishkumar
 
K-means Clustering Algorithm with Matlab Source code
K-means Clustering Algorithm with Matlab Source code
gokulprasath06
 
K means clustering
K means clustering
Ahmedasbasb
 
CC282 Unsupervised Learning (Clustering) Lecture 7 slides for ...
CC282 Unsupervised Learning (Clustering) Lecture 7 slides for ...
butest
 
K-means clustering algorithm
K-means clustering algorithm
Vinit Dantkale
 
K mean-clustering algorithm
K mean-clustering algorithm
parry prabhu
 
Cluster analysis using k-means method in R
Cluster analysis using k-means method in R
Vladimir Bakhrushin
 
K Means Clustering Algorithm | K Means Example in Python | Machine Learning A...
K Means Clustering Algorithm | K Means Example in Python | Machine Learning A...
Edureka!
 
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
K Means Clustering Algorithm | K Means Clustering Example | Machine Learning ...
Simplilearn
 
Customer Segmentation using Clustering
Customer Segmentation using Clustering
Dessy Amirudin
 
K means clustering algorithm
K means clustering algorithm
Darshak Mehta
 
An improvement in k mean clustering algorithm using better time and accuracy
An improvement in k mean clustering algorithm using better time and accuracy
ijpla
 
K means clustering
K means clustering
keshav goyal
 
K mean-clustering
K mean-clustering
PVP College
 

Viewers also liked (8)

Cardiac Image Analysis based on K Means Clustering
Cardiac Image Analysis based on K Means Clustering
NAVEEN TOKAS
 
K means and dbscan
K means and dbscan
Yan Xu
 
A study and comparison of different image segmentation algorithms
A study and comparison of different image segmentation algorithms
Manje Gowda
 
PPT on BRAIN TUMOR detection in MRI images based on IMAGE SEGMENTATION
PPT on BRAIN TUMOR detection in MRI images based on IMAGE SEGMENTATION
khanam22
 
Image segmentation ppt
Image segmentation ppt
Gichelle Amon
 
IMAGE SEGMENTATION.
IMAGE SEGMENTATION.
Tawose Olamide Timothy
 
K means Clustering Algorithm
K means Clustering Algorithm
Kasun Ranga Wijeweera
 
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
Carol Smith
 
Cardiac Image Analysis based on K Means Clustering
Cardiac Image Analysis based on K Means Clustering
NAVEEN TOKAS
 
K means and dbscan
K means and dbscan
Yan Xu
 
A study and comparison of different image segmentation algorithms
A study and comparison of different image segmentation algorithms
Manje Gowda
 
PPT on BRAIN TUMOR detection in MRI images based on IMAGE SEGMENTATION
PPT on BRAIN TUMOR detection in MRI images based on IMAGE SEGMENTATION
khanam22
 
Image segmentation ppt
Image segmentation ppt
Gichelle Amon
 
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
Carol Smith
 
Ad

Similar to Intro to MATLAB and K-mean algorithm (20)

Matlab booklet
Matlab booklet
Sourabh Bhattacharya
 
Digital communication lab lectures
Digital communication lab lectures
marwaeng
 
1. Introduction to Computing - MATLAB.pptx
1. Introduction to Computing - MATLAB.pptx
tgkfkj9n2k
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
Mukesh Kumar
 
Basic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptx
PremanandS3
 
Matrix Indexing in MATLAB - MATLAB & Simulink.pdf
Matrix Indexing in MATLAB - MATLAB & Simulink.pdf
ssuser6bbf6b1
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
joellivz
 
1. Introduction.pptx
1. Introduction.pptx
SungaleliYuen
 
MATLAB-Introd.ppt
MATLAB-Introd.ppt
kebeAman
 
Introduction to MATLAB
Introduction to MATLAB
Dun Automation Academy
 
Dsp manual completed2
Dsp manual completed2
bilawalali74
 
EPE821_Lecture3.pptx
EPE821_Lecture3.pptx
Ihtisham Uddin
 
Lecture 3.pptx
Lecture 3.pptx
SungaleliYuen
 
matlab_tutorial.ppt
matlab_tutorial.ppt
naveen_setty
 
matlab_tutorial.ppt
matlab_tutorial.ppt
aboma2hawi
 
matlab_tutorial for student in the first
matlab_tutorial for student in the first
naghamsalimmohammed
 
MatlabIntro.ppt
MatlabIntro.ppt
ShwetaPandey248972
 
MatlabIntro.ppt
MatlabIntro.ppt
konkatisandeepkumar
 
MatlabIntro.ppt
MatlabIntro.ppt
ssuser772830
 
MatlabIntro.ppt
MatlabIntro.ppt
Rajmohan Madasamy
 
Digital communication lab lectures
Digital communication lab lectures
marwaeng
 
1. Introduction to Computing - MATLAB.pptx
1. Introduction to Computing - MATLAB.pptx
tgkfkj9n2k
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
Mukesh Kumar
 
Basic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptx
PremanandS3
 
Matrix Indexing in MATLAB - MATLAB & Simulink.pdf
Matrix Indexing in MATLAB - MATLAB & Simulink.pdf
ssuser6bbf6b1
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
joellivz
 
1. Introduction.pptx
1. Introduction.pptx
SungaleliYuen
 
MATLAB-Introd.ppt
MATLAB-Introd.ppt
kebeAman
 
Dsp manual completed2
Dsp manual completed2
bilawalali74
 
matlab_tutorial.ppt
matlab_tutorial.ppt
naveen_setty
 
matlab_tutorial.ppt
matlab_tutorial.ppt
aboma2hawi
 
matlab_tutorial for student in the first
matlab_tutorial for student in the first
naghamsalimmohammed
 
Ad

Recently uploaded (20)

Complete University of Calculus :: 2nd edition
Complete University of Calculus :: 2nd edition
Shabista Imam
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
Introduction to Python Programming Language
Introduction to Python Programming Language
merlinjohnsy
 
Structured Programming with C++ :: Kjell Backman
Structured Programming with C++ :: Kjell Backman
Shabista Imam
 
Industrial internet of things IOT Week-3.pptx
Industrial internet of things IOT Week-3.pptx
KNaveenKumarECE
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
How to Un-Obsolete Your Legacy Keypad Design
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
20CE404-Soil Mechanics - Slide Share PPT
20CE404-Soil Mechanics - Slide Share PPT
saravananr808639
 
Structural Wonderers_new and ancient.pptx
Structural Wonderers_new and ancient.pptx
nikopapa113
 
CST413 KTU S7 CSE Machine Learning Clustering K Means Hierarchical Agglomerat...
CST413 KTU S7 CSE Machine Learning Clustering K Means Hierarchical Agglomerat...
resming1
 
special_edition_using_visual_foxpro_6.pdf
special_edition_using_visual_foxpro_6.pdf
Shabista Imam
 
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
Microwatt: Open Tiny Core, Big Possibilities
Microwatt: Open Tiny Core, Big Possibilities
IBM
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
retina_biometrics ruet rajshahi bangdesh.pptx
retina_biometrics ruet rajshahi bangdesh.pptx
MdRakibulIslam697135
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
Rapid Prototyping for XR: Lecture 2 - Low Fidelity Prototyping.
Rapid Prototyping for XR: Lecture 2 - Low Fidelity Prototyping.
Mark Billinghurst
 
LECTURE 7 COMPUTATIONS OF LEVELING DATA APRIL 2025.pptx
LECTURE 7 COMPUTATIONS OF LEVELING DATA APRIL 2025.pptx
rr22001247
 
Complete University of Calculus :: 2nd edition
Complete University of Calculus :: 2nd edition
Shabista Imam
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
Introduction to Python Programming Language
Introduction to Python Programming Language
merlinjohnsy
 
Structured Programming with C++ :: Kjell Backman
Structured Programming with C++ :: Kjell Backman
Shabista Imam
 
Industrial internet of things IOT Week-3.pptx
Industrial internet of things IOT Week-3.pptx
KNaveenKumarECE
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
20CE404-Soil Mechanics - Slide Share PPT
20CE404-Soil Mechanics - Slide Share PPT
saravananr808639
 
Structural Wonderers_new and ancient.pptx
Structural Wonderers_new and ancient.pptx
nikopapa113
 
CST413 KTU S7 CSE Machine Learning Clustering K Means Hierarchical Agglomerat...
CST413 KTU S7 CSE Machine Learning Clustering K Means Hierarchical Agglomerat...
resming1
 
special_edition_using_visual_foxpro_6.pdf
special_edition_using_visual_foxpro_6.pdf
Shabista Imam
 
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
Microwatt: Open Tiny Core, Big Possibilities
Microwatt: Open Tiny Core, Big Possibilities
IBM
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
retina_biometrics ruet rajshahi bangdesh.pptx
retina_biometrics ruet rajshahi bangdesh.pptx
MdRakibulIslam697135
 
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Tally.ERP 9 at a Glance.book - Tally Solutions .pdf
Shabista Imam
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
Rapid Prototyping for XR: Lecture 2 - Low Fidelity Prototyping.
Rapid Prototyping for XR: Lecture 2 - Low Fidelity Prototyping.
Mark Billinghurst
 
LECTURE 7 COMPUTATIONS OF LEVELING DATA APRIL 2025.pptx
LECTURE 7 COMPUTATIONS OF LEVELING DATA APRIL 2025.pptx
rr22001247
 

Intro to MATLAB and K-mean algorithm

  • 2.  MATLAB (Matrix Laboratory) [1]  MATLAB(matrix laboratory) is a multi-paradigm numerical computing environment and fourth-generation programming language.  Developed by Math Works, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, Java and Fortran. MATLAB
  • 3.  MATLAB (Matrix Laboratory) [2]  Although MATLAB is intended primarily for numerical computing, an option al toolbox uses the MuPAD symbolic engine, allowing access to symbolic computing capabilities. An additional package, Simulink, adds graphical multi-domain simulation and Model-Based Design for dynamic and embedded systems.  In 2004, MATLAB had around one million users across industry and academia. MATLAB users come from various backgrounds of engineering, science, and economics. MATLAB is widely used in academic and research institutions as well as industrial enterprises. MATLAB
  • 4.  Commands  >>433.12*15.7  ans=6.8000e+003  MATLAB spits out the answer to our query conveniently named ans.  This is a variable or symbolic name that can be used to represent the value later.  >>x=5*6  X=30 MATLAB
  • 5.  Commands  To write the multiplication ab, in MATLAB we type a*b  For division, the quantity a÷b is typed as a/b. This type of division is referred to as right division.  MATLAB also allows another way to enter division, called left division. We can enter the quantity by a typing the slash mark used for division in the opposite way, that is, we use a back slash instead of a forward slash ab MATLAB
  • 6.  Commands  Exponentiation a to the power b is entered in the following way a ^ b  Finally, addition and subtraction are entered in the usual way  a + b  a –b MATLAB
  • 7.  Commands  Individual matrix and vector entries can be referenced with indices inside parentheses. For example, A(2,3) denotes the entry in the second row, third column of matrix A.  A=[123;456;-179]  A(2,3)  Create a column vector, x, with:  x=[321]’  Or equivalently:  x=[3;2;1] MATLAB
  • 8.  Commands  The relational operators in MATLAB are:  < less than  > greater than  <= less than or equal  >= greater than or equal  == equal  ~= not equal  Note that = is used in an assignment statement whereas == is a relational operator. MATLAB
  • 9.  Commands  Logical operators:  Relational operators may be connected by logical operators:  & and  | or  ~ not  && short-circuit and  || short-circuit or MATLAB
  • 10.  Commands  Inner product or dot product  .* Array multiply:  X.*Y denotes element-by-element multiplication. X and Y must have the same dimensions unless one is a scalar.  * Matrix multiply:  X*Y is the matrix product of X and Y. Any scalar (a 1-by- 1 matrix) may multiply anything. Otherwise, the number of columns of X must equal the number of rows of Y. MATLAB
  • 11.  Commands  /Slash or right matrix divide:  A/B is the matrix division of B into A, which is roughly the same as A*INV(B), except it is computed in a different way. More precisely, A/B = (B'A')'.  Backslash or left matrix divide:  AB is the matrix division of A into B, which is roughly the same as INV(A)*B, except it is computed in a different way. If A is an N-by-N matrix and B is a column vector with N components, or a matrix with several such columns, then X=AB is the solution to the equation singular MATLAB
  • 12.  Commands  To divide Matrices, element-by-element, the following formula is useful A./B  A = [2 4 6 8]; B = [2 2 3 1];  C = A./B  % C = [1 2 2 8]  Array left division is indicated by writing C = A.B (this is the same as C = B./A):  C = A.B  % C = [1.0000 0.5000 0.5000 0.125] MATLAB
  • 13.  Commands  fix()  fix(X) rounds the elements of X to the nearest integers towards zero.  >> fix(5.5)  ans =  5  >> fix(5.9)  ans =  5 MATLAB
  • 14.  Commands  rand()  rand():returns an n-by-n matrix containing pseudo random values drawn from the standard uniform distribution on the open interval(0,1).  >> n = rand(1,10)  n =0.1576 0.9706 0.9572 0.4854 0.8003 0.1419 0.4218 0.9157 0.7922 0.9595  >> n = fix(10*rand(1,10))  n =8 9 1 9 6 0 2 5 9 9 MATLAB
  • 15.  Commands  Question: Simulate the outcomes of 1000 biased coin tosses with p[Head] = 0.3  Solution:  n = 1000;  randomNumber= rand(n,1);  Heads = randomNumber<= 0.3;  totalNumberOfHeads= sum(Heads);  probabilityOfHeads= totalNumberOfHeads/n; MATLAB
  • 16.  Commands  Plot(x,y) plot the graph between x and y.  X and y are the vectors of same lengths.  >>X=1:10  >>y=11:20  >> plot(x,y) MATLAB
  • 17.  Commands  Two or more than two graphs plot on at same time with hold on function  x=-5:5  y=x.*x  plot(x,y)  hold on  a=1:5  b=1:5  plot(a,b) MATLAB
  • 19. INTRODUCTION- What is clustering?  Clustering is the classification of objects into different groups, or more precisely, the partitioning of a data set into subsets (clusters), so that the data in each subset (ideally) share some common trait - often according to some defined distance measure.
  • 20. Common Distance measures:  Distance measure will determine how the similarity of two elements is calculated and it will influence the shape of the clusters. They include: 1. The Euclidean distance (also called 2-norm distance) is given by: 2. The Manhattan distance (also called taxicab norm or 1- norm) is given by:
  • 21. K-MEANS CLUSTERING  The k-means algorithm is an algorithm to cluster n objects based on attributes into k partitions, where k < n.
  • 22. K-MEANS CLUSTERING  Simply speaking k-means clustering is an algorithm to classify or to group the objects based on attributes/features into K number of group.  K is positive integer number.  The grouping is done by minimizing the sum of squares of distances between data and the corresponding cluster centroid.
  • 23. How the K-Mean Clustering algorithm works?
  • 24.  Step 1: Begin with a decision on the value of k = number of clusters .  Step 2: Put any initial partition that classifies the data into k clusters. You may assign the training samples randomly,or systematically as the following: 1.Take the first k training sample as single- element clusters 2. Assign each of the remaining (N-k) training sample to the cluster with the nearest centroid. After each assignment, recompute the centroid of the gaining cluster.
  • 25.  Step 3: Take each sample in sequence and compute its distance from the centroid of each of the clusters. If a sample is not currently in the cluster with the closest centroid, switch this sample to that cluster and update the centroid of the cluster gaining the new sample and the cluster losing the sample.  Step 4 . Repeat step 3 until convergence is achieved, that is until a pass through the training sample causes no new assignments.
  • 26. Applications of K-Mean Clustering  It is relatively efficient and fast. It computes result at O(tkn), where n is number of objects or points, k is number of clusters and t is number of iterations.  k-means clustering can be applied to machine learning or data mining  Used on acoustic data in speech understanding to convert waveforms into one of k categories (known as Vector Quantization or Image Segmentation).  Also used for choosing color palettes on old fashioned graphical display devices and Image Quantization.

Editor's Notes

  • #28: %Image 1 k=2,5,10% k=2; A=imread(&amp;apos;pic1.jpg&amp;apos;); A=im2double(A); RGB_matrix = reshape(A,size(A,1)*size(A,2),size(A,3)); clusterPointAllocationMatrix=zeros(size(RGB_matrix ,1),1); p_centroids=zeros(k,3);%previous centroids% centroids = zeros(k,3); %pick random cluster points from matrix% for i=1:k centroids(i,:)=RGB_matrix(randi([1 size(RGB_matrix ,1)],1,1),:); end [r,c]=size(RGB_matrix); %1st column=sum of R ;2nd column=sum of G;3rd cloumn =sum of B; column 4= number of values; index number represent the group number% pointsInfo = zeros(k,4); while ~isequal(centroids,p_centroids) p_centroids=centroids; pointsInfo = zeros(k,4); for j=1:r close=inf; group=0; point1=RGB_matrix(j,:); for l=1:k point2=centroids(l,:); dist=sqrt((point1(1,1)-point2(1,1))^2 + (point1(1,2)-point2(1,2))^2 + (point1(1,3)-point2(1,3))^2); if( dist &amp;lt; close ) close=dist; group=l; end end clusterPointAllocationMatrix(j,1)=group; pointsInfo(group,1)=pointsInfo(group,1)+point1(1,1);%R% pointsInfo(group,2)=pointsInfo(group,2)+point1(1,2);%G% pointsInfo(group,3)=pointsInfo(group,3)+point1(1,3);%B% pointsInfo(group,4)=pointsInfo(group,4)+1;%number of values related to that group% end %updation of centroids% for m=1:k centroids(m,1)=double(pointsInfo(m,1)/pointsInfo(m,4)); centroids(m,2)=double(pointsInfo(m,2)/pointsInfo(m,4)); centroids(m,3)=double(pointsInfo(m,3)/pointsInfo(m,4)); end end newRGB_matrix =zeros(r,c); for o=1:r newRGB_matrix(o,:)=centroids(clusterPointAllocationMatrix(o,1),:); end B=reshape(newRGB_matrix, size(A,1), size(A,2), size(A,3)); C=im2uint8(B) imshow(C);