SlideShare a Scribd company logo
Matlab Intro
Outline
􀁺 Matlab introduction
􀁺 Matlab elements
􀁺 Types
􀁺 Variables
􀁺 Matrices
Matlab introduction
􀁺 Matlab is a program for doing
numerical computation. It was
originally designed for solving linear
algebra type problems using
matrices. It’s name is derived from
MATrix LABoratory.
􀁺 Matlab is also a programming
language that currently is widely
used as a platform for
developing tools for Machine
Learning
Matlab Matrices
􀁺 Matlab treats all variables as matrices.
For our purposes a matrix can be thought
of as an array, in fact, that is how it is
stored.
􀁺 Vectors are special forms of matrices
and contain only one row OR one column.
􀁺 Scalars are matrices with only one row
AND one column
Matlab Matrices
􀁺 A matrix with only one row is called a
row vector. A row vector can be created in
Matlab as follows (note the commas):
» rowvec = [12 , 14 , 63]
rowvec =
12 14 63
Matlab Matrices
􀁺 A matrix with only one column is
called a column vector. A column
vector can be created in MATLAB as
follows (note the semicolons):
» colvec = [13 ; 45 ; -2]
colvec =
13
45
-2
Matlab Matrices
􀁺 A matrix can be created in Matlab
as follows (note the commas AND
semicolons):
» matrix =
[1 , 2 , 3 ; 4 , 5 ,6 ; 7 , 8 , 9]
matrix =
1 2 3
4 5 6
7 8 9
Extracting a Sub-Matrix
􀁺 A portion of a matrix can be extracted and
stored in a smaller matrix by specifying the
names of both matrices and the rows and
columns to extract.
The syntax is:
sub_matrix = matrix ( r1 : r2 , c1 : c2 ) ;
where r1 and r2 specify the beginning and
ending rows and c1 and c2 specify the
beginning and ending columns to be
extracted to make the new matrix.
Matlab Matrices
􀁺 A column vector can be extracted from a matrix. As an
example we create a matrix below:
» matrix=[1,2,3;4,5,6;7,8,9]
matrix =
1 2 3
4 5 6
7 8 9
􀁺 Here we extract column 2 of the matrix and
make a column vector:
» col_two=matrix( : , 2)
col_two =
2
5
8
Matlab Matrices
􀁺 A row vector can be extracted from a matrix. As an example
we create a matrix below:
» matrix=[1,2,3;4,5,6;7,8,9]
matrix =
1 2 3
4 5 6
7 8 9
􀁺 Here we extract row 2 of the matrix and make a row vector.
Note that the 2:2 specifies the second row and the 1:3
specifies which columns of the row.
» rowvec=matrix(2 : 2 , 1 : 3)
rowvec =
4 5 6
Colon Operator
j:k is the same as [j,j+1,...,k] is empty if j > k
j:i:k is the same as [j,j+i,j+2i, ..,k] is empty if i > 0 and j > k or if
i < 0 and j < k
A(:,j) is the j-th column of A
A(i,:) is the i-th row of A
A(:,:) is the equivalent two-dimensional array. For matrices this
is the same as A.
A(j:k) is A(j), A(j+1),...,A(k)
A(:,j:k) is A(:,j), A(:,j+1),...,A(:,k)
A(:,:,k) is the k-th page of three-dimensional array A.
Matlab Matrices
􀁺 Accessing Single Elements of a Matrix
A(i,j)
􀁺 Accessing Multiple Elements of a Matrix
A(1,4) + A(2,4) + A(3,4) + A(4,4)
􀃎 sum(A(1:4,4)) or sum(A(:,end))
The keyword end refers to the last row or
column.
􀁺 Deleting Rows and Columns
to delete the second column of X, use
X(:,2) = []
􀁺 Concatenating Matrices A and B
C=[A;B]
Some matrix functions in Matlab
􀁺 X = ones(r,c) % Creates matrix full with
ones
􀁺 X = zeros(r,c) % Creates matrix full with
zeros
􀁺 X = rand(r,c) % Creates matrix with
With random numbers between (0, 1]
􀁺 [r,c] = size(A) % Return dimensions of
matrix A
􀁺 + - * / % Standard operations
􀁺 .+ .- .* ./ % Wise addition, substraction,…
􀁺 v = sum(A) % Vector with sum of columns
Commands
clc Clears Command window.
clear Removes variables from memory.
exist Checks for existence of file or variable.
help Searches for a help topic.
lookfor Searches help entries for a keyword.
quit Stops MATLAB.
who Lists current variables.
whos Lists current variables (long display).
ans Most recent answer.
find Finds indices of nonzero elements.
length Computers number of elements.
max Returns largest element.
min Returns smallest element.
size Computes array size.
sort Sorts each column.
sum Sums each column.
Excersises
Ad

More Related Content

Similar to Matlab Introduction Simulink and Basics ds (20)

Matlab an Introduction_Lecture_for all.ppt
Matlab an Introduction_Lecture_for all.pptMatlab an Introduction_Lecture_for all.ppt
Matlab an Introduction_Lecture_for all.ppt
PoojaSharma693700
 
Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
THEMASTERBLASTERSVID
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
prashantkumarchinama
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
Dr. Krishna Mohbey
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Santosh V
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
Ravibabu Kancharla
 
Chap1 Matrix and Linear Algerbra.s,jspptx
Chap1 Matrix and Linear Algerbra.s,jspptxChap1 Matrix and Linear Algerbra.s,jspptx
Chap1 Matrix and Linear Algerbra.s,jspptx
yassinebrh31
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Dun Automation Academy
 
5_Vectors & Matrices for Engineers .pptx
5_Vectors & Matrices for Engineers .pptx5_Vectors & Matrices for Engineers .pptx
5_Vectors & Matrices for Engineers .pptx
SungaleliYuen
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
joellivz
 
Interactive Computation With MATLAB.pptx
Interactive Computation With MATLAB.pptxInteractive Computation With MATLAB.pptx
Interactive Computation With MATLAB.pptx
Sufi Yasir Raza
 
1. Introduction to Computing - MATLAB.pptx
1. Introduction to Computing -  MATLAB.pptx1. Introduction to Computing -  MATLAB.pptx
1. Introduction to Computing - MATLAB.pptx
tgkfkj9n2k
 
Basic concepts in_matlab
Basic concepts in_matlabBasic concepts in_matlab
Basic concepts in_matlab
Mohammad Alauddin
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
krajeshk1980
 
Ses 2 matrix opt
Ses 2 matrix optSes 2 matrix opt
Ses 2 matrix opt
metnashikiom2011-13
 
Matlab Programming Help Research Guidance
Matlab Programming Help Research GuidanceMatlab Programming Help Research Guidance
Matlab Programming Help Research Guidance
Matlab Simulation
 
Lecture 3.pptx
Lecture 3.pptxLecture 3.pptx
Lecture 3.pptx
SungaleliYuen
 
Matlab
MatlabMatlab
Matlab
Maria Akther
 
Matlab colon notation
Matlab colon notationMatlab colon notation
Matlab colon notation
pramodkumar1804
 
Matlab booklet
Matlab bookletMatlab booklet
Matlab booklet
Sourabh Bhattacharya
 
Matlab an Introduction_Lecture_for all.ppt
Matlab an Introduction_Lecture_for all.pptMatlab an Introduction_Lecture_for all.ppt
Matlab an Introduction_Lecture_for all.ppt
PoojaSharma693700
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
prashantkumarchinama
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
Dr. Krishna Mohbey
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Santosh V
 
Chap1 Matrix and Linear Algerbra.s,jspptx
Chap1 Matrix and Linear Algerbra.s,jspptxChap1 Matrix and Linear Algerbra.s,jspptx
Chap1 Matrix and Linear Algerbra.s,jspptx
yassinebrh31
 
5_Vectors & Matrices for Engineers .pptx
5_Vectors & Matrices for Engineers .pptx5_Vectors & Matrices for Engineers .pptx
5_Vectors & Matrices for Engineers .pptx
SungaleliYuen
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
joellivz
 
Interactive Computation With MATLAB.pptx
Interactive Computation With MATLAB.pptxInteractive Computation With MATLAB.pptx
Interactive Computation With MATLAB.pptx
Sufi Yasir Raza
 
1. Introduction to Computing - MATLAB.pptx
1. Introduction to Computing -  MATLAB.pptx1. Introduction to Computing -  MATLAB.pptx
1. Introduction to Computing - MATLAB.pptx
tgkfkj9n2k
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
krajeshk1980
 
Matlab Programming Help Research Guidance
Matlab Programming Help Research GuidanceMatlab Programming Help Research Guidance
Matlab Programming Help Research Guidance
Matlab Simulation
 

Recently uploaded (20)

Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt
rakshaiya16
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
JRR Tolkien’s Lord of the Rings: Was It Influenced by Nordic Mythology, Homer...
Reflections on Morality, Philosophy, and History
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Journal of Soft Computing in Civil Engineering
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning ModelsMode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Mode-Wise Corridor Level Travel-Time Estimation Using Machine Learning Models
Journal of Soft Computing in Civil Engineering
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
Generative AI & Large Language Models Agents
Generative AI & Large Language Models AgentsGenerative AI & Large Language Models Agents
Generative AI & Large Language Models Agents
aasgharbee22seecs
 
Autodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User InterfaceAutodesk Fusion 2025 Tutorial: User Interface
Autodesk Fusion 2025 Tutorial: User Interface
Atif Razi
 
Uses of drones in civil construction.pdf
Uses of drones in civil construction.pdfUses of drones in civil construction.pdf
Uses of drones in civil construction.pdf
surajsen1729
 
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdfML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
ML_Unit_V_RDC_ASSOCIATION AND DIMENSIONALITY REDUCTION.pdf
rameshwarchintamani
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
acid base ppt and their specific application in food
acid base ppt and their specific application in foodacid base ppt and their specific application in food
acid base ppt and their specific application in food
Fatehatun Noor
 
Evonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdfEvonik Overview Visiomer Specialty Methacrylates.pdf
Evonik Overview Visiomer Specialty Methacrylates.pdf
szhang13
 
2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt2.3 Genetically Modified Organisms (1).ppt
2.3 Genetically Modified Organisms (1).ppt
rakshaiya16
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdfSmart City is the Future EN - 2024 Thailand Modify V1.0.pdf
Smart City is the Future EN - 2024 Thailand Modify V1.0.pdf
PawachMetharattanara
 
Construction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil EngineeringConstruction Materials (Paints) in Civil Engineering
Construction Materials (Paints) in Civil Engineering
Lavish Kashyap
 
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
01.คุณลักษณะเฉพาะของอุปกรณ์_pagenumber.pdf
PawachMetharattanara
 
Nanometer Metal-Organic-Framework Literature Comparison
Nanometer Metal-Organic-Framework  Literature ComparisonNanometer Metal-Organic-Framework  Literature Comparison
Nanometer Metal-Organic-Framework Literature Comparison
Chris Harding
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Agents chapter of Artificial intelligence
Agents chapter of Artificial intelligenceAgents chapter of Artificial intelligence
Agents chapter of Artificial intelligence
DebdeepMukherjee9
 
Ad

Matlab Introduction Simulink and Basics ds

  • 2. Outline 􀁺 Matlab introduction 􀁺 Matlab elements 􀁺 Types 􀁺 Variables 􀁺 Matrices
  • 3. Matlab introduction 􀁺 Matlab is a program for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. It’s name is derived from MATrix LABoratory. 􀁺 Matlab is also a programming language that currently is widely used as a platform for developing tools for Machine Learning
  • 4. Matlab Matrices 􀁺 Matlab treats all variables as matrices. For our purposes a matrix can be thought of as an array, in fact, that is how it is stored. 􀁺 Vectors are special forms of matrices and contain only one row OR one column. 􀁺 Scalars are matrices with only one row AND one column
  • 5. Matlab Matrices 􀁺 A matrix with only one row is called a row vector. A row vector can be created in Matlab as follows (note the commas): » rowvec = [12 , 14 , 63] rowvec = 12 14 63
  • 6. Matlab Matrices 􀁺 A matrix with only one column is called a column vector. A column vector can be created in MATLAB as follows (note the semicolons): » colvec = [13 ; 45 ; -2] colvec = 13 45 -2
  • 7. Matlab Matrices 􀁺 A matrix can be created in Matlab as follows (note the commas AND semicolons): » matrix = [1 , 2 , 3 ; 4 , 5 ,6 ; 7 , 8 , 9] matrix = 1 2 3 4 5 6 7 8 9
  • 8. Extracting a Sub-Matrix 􀁺 A portion of a matrix can be extracted and stored in a smaller matrix by specifying the names of both matrices and the rows and columns to extract. The syntax is: sub_matrix = matrix ( r1 : r2 , c1 : c2 ) ; where r1 and r2 specify the beginning and ending rows and c1 and c2 specify the beginning and ending columns to be extracted to make the new matrix.
  • 9. Matlab Matrices 􀁺 A column vector can be extracted from a matrix. As an example we create a matrix below: » matrix=[1,2,3;4,5,6;7,8,9] matrix = 1 2 3 4 5 6 7 8 9 􀁺 Here we extract column 2 of the matrix and make a column vector: » col_two=matrix( : , 2) col_two = 2 5 8
  • 10. Matlab Matrices 􀁺 A row vector can be extracted from a matrix. As an example we create a matrix below: » matrix=[1,2,3;4,5,6;7,8,9] matrix = 1 2 3 4 5 6 7 8 9 􀁺 Here we extract row 2 of the matrix and make a row vector. Note that the 2:2 specifies the second row and the 1:3 specifies which columns of the row. » rowvec=matrix(2 : 2 , 1 : 3) rowvec = 4 5 6
  • 11. Colon Operator j:k is the same as [j,j+1,...,k] is empty if j > k j:i:k is the same as [j,j+i,j+2i, ..,k] is empty if i > 0 and j > k or if i < 0 and j < k A(:,j) is the j-th column of A A(i,:) is the i-th row of A A(:,:) is the equivalent two-dimensional array. For matrices this is the same as A. A(j:k) is A(j), A(j+1),...,A(k) A(:,j:k) is A(:,j), A(:,j+1),...,A(:,k) A(:,:,k) is the k-th page of three-dimensional array A.
  • 12. Matlab Matrices 􀁺 Accessing Single Elements of a Matrix A(i,j) 􀁺 Accessing Multiple Elements of a Matrix A(1,4) + A(2,4) + A(3,4) + A(4,4) 􀃎 sum(A(1:4,4)) or sum(A(:,end)) The keyword end refers to the last row or column. 􀁺 Deleting Rows and Columns to delete the second column of X, use X(:,2) = [] 􀁺 Concatenating Matrices A and B C=[A;B]
  • 13. Some matrix functions in Matlab 􀁺 X = ones(r,c) % Creates matrix full with ones 􀁺 X = zeros(r,c) % Creates matrix full with zeros 􀁺 X = rand(r,c) % Creates matrix with With random numbers between (0, 1] 􀁺 [r,c] = size(A) % Return dimensions of matrix A 􀁺 + - * / % Standard operations 􀁺 .+ .- .* ./ % Wise addition, substraction,… 􀁺 v = sum(A) % Vector with sum of columns
  • 14. Commands clc Clears Command window. clear Removes variables from memory. exist Checks for existence of file or variable. help Searches for a help topic. lookfor Searches help entries for a keyword. quit Stops MATLAB. who Lists current variables. whos Lists current variables (long display). ans Most recent answer. find Finds indices of nonzero elements. length Computers number of elements. max Returns largest element. min Returns smallest element. size Computes array size. sort Sorts each column. sum Sums each column.
  翻译: