SlideShare a Scribd company logo
1 of 35
Introduction to MATLAB
Md. Menhazul Abedin
Lecturer, Statistics Discipline
Khulna university
menhaz70@gmail.com
What is MATLAB
• High level language for technical computing
• Stands for MATrix LABoratory
• Everything is a matrix - easy to do linear
algebra
MATLAB Desktop
Menu and toolbar
CommandHistory
Workspace
Valid variables Names
• A valid variable name starts with a letter,
followed by letters, digits, or underscores.
• MATLAB® is casesensitive, so A and a are not the
same variable.
• The maximum length of a variable name is the
value that the namelengthmax command returns.
• You cannot define variables with the same names
as MATLAB keywords, such as if or end. For a
complete list, run the iskeyword command.
Matlab keywords….
• Keywords are must not variable name
• 'break' 'case' 'catch' 'classdef' 'continue' 'else'
'elseif' 'end' 'for' 'function' 'global' 'if' 'otherwise'
'parfor' 'persistent' 'return' 'spmd' 'switch' 'try'
'while'
How to run?
• If program in command space press “ enter”
• If in open script then block command and
presss F9.
Matrices & Vectors
• All (almost) entities in MATLAB are matrices
• Easy to define:
• Use ‘,’ or ‘ ’ to separate row elements
• use ‘;’ to separate rows
>> A = [1 3; 5 8]
A = 1 3
5 8
>> A = [1,3; 5,8]
A = 1 3
5 8
Matrices & Vectors
• Order of Matrix -
– m=no. of rows,
– n=no. of columns
• Vectors - special cases
– n = 1 column vector
– m = 1 row vector

m  n
Simple algebraic operations
Addition +
Subtraction -
Multiplication *
Division /
Power ^
Logarithm log()
Exponential Exp()
Square root sqrt()
Absolute value abs()
Element wise operations…
.*element-by-element multiplication
./element-by-element division
.^ element-by-element power
Operators (relational, logical)
• == Equal to
• ~= Not equal to
• < Strictly smaller
• > Strictly greater
• <= Smaller than or equal to
• >= Greater than equal to
• & And operator
• | Or operator
Sequences…….
• t =1:10
t =
1 2 3 4 5 6 7 8 9 10
• k =2:-0.5:-1
k =
2 1.5 1 0.5 0 -0.5 -1
• y=[2:2:12]
y=
2 4 6 8 10 12
• B = [1:4; 5:8]
x =
1 2 3 4
5 6 7 8
Some practice…….
• Do some mathematical operations as like as
calculator (addition, subtraction,
multiplication, division, log, square root,
power and so on)
Matrix...
• a vector x = [1 2 5 1]
x =
1 2 5 1
• a matrix x = [1 2 3; 5 1 4; 3 2 -1]
x =
1 2 3
5 1 4
3 2 -1
Special matrix….
• Identity matrix= eye (row,column)
• One matrix= ones(row,column)
• Zero marix= zeros (row,column)
Matrix operations…
• Let A be a matrix….
• Determinant= det(A)
• Transpose= A’
• Rank = rank(A)
• Inverse= inv(A)
• Trace = trace(A)
• Eigen value=eig(A)
• Eigen value and vector= [V,D] = eig(A)
• Matrix multiplication= A*B
• Matrix multiplication= A.*B [elementwise]
• Singular values= svd(A)
Cont…
• diag diagonal atrix
• triu upper triangular matrix
• tril lower triangular matri
• rand randomly generated matrix
• C=rand(5,4)
• triu(C)
• tril(C)
• diag([0.9092;0.5163;0.2661])
Cont…
• Length of a vector= length(x)
• Size or dimension of matrix= size(A)
• Replication of same number=
repmat(number,m,n)
Basic statistical building function…
• Let be a sample
• Mean= mean(x)
• Median=median(x)
• Mode= mode(x)
• Variance=var(x)
• Standard deviation=std(x)
• Minimum= min(x)
• Maximum= max(x)
• Summation=sum(x)
nxxxx ,...,, 21
Data preprocessing…(Missing value)
• a = magic(3); a(2,2) = NaN
• a = 8 1 6
3 NaN 7
4 9 2
sum(a)
ans =
15 NaN 15
sum(a) ans = 15 NaN 15
sum(a,'omitnan')
ans = 15 10 15
Class of
variables=class(A)
Random number generation….
• Normal distribution:
normrnd(mu,sigma) for a single value
normrnd(mu,sigma,m,n) or
normrnd(mu,sigma[m,n]) for matrix having
m row and ncolumn
• Poisson distribution:
poissrnd(lamda)
poissrnd(lamda,m,n)
poissrnd(lamda,[m,n])
Binomial distribution:
binornd(N,P)
binornd(N,P,m,n)
binornd(N,P,[m,n])
Cont…
• Geometric distribution:
geornd(p)
geornd(p,m,n)
geornd(p,[m,n])
• Beta distribution:
betarnd(A,B)
betarnd(A,B,m,n)
betarnd(A,B,[m,n])
Exponential distribution:
exprnd(mu)
exprnd(mu,m,n)
exprnd(mu,[m,n])
Gamma distribution:
gamrd(A,B)
gamrnd(A,B,m,n)
gamrnd(A,B,[m,n])
Cont…
• Standard normal distribution:
randn return single value
randn(n) return n-by-n square matrix
randn(r,c) return r-by-c matrx
Covariance of Matrix
• C = cov(A,B)
returns the covariance between two random
variables A and B.
• C = cov(A)
returns the matrix of correlation
coefficient for A, where the columns
of A represent random variables and the rows
represent observations.
Example…
• A = [5 0 3 7; 1 -5 7 3; 4 9 8 10];
C = cov(A)
• A = [3 6 4]; B = [7 12 -9];
cov(A,B)
Correlation coefficient…
• R = corrcoef(A)
returns the matrix of correlation
coefficient for A, where the columns
of A represent random variables and the rows
represent observations.
• R= corrcoef(A,B)
returns coefficients between two random
variables A and B.
Example…..
• x = randn(6,1);
• y = randn(6,1);
• A = [x y 2*y+3];
• R = corrcoef(A)
• A = randn(10,1);
• B = randn(10,1);
• R = corrcoef(A,B)
Ploting…
• x vector
• y vector
• Z vector
plot(x,y) 2D line diagram
plot(x,y,z) 3D line diagram
scatter(x,y) scatter diagram
scatter(x,y,z) 3D scatter diagram
bar(x) bar diagram
bar3(x) 3D bar diagram
hist(x) histogram
boxplot(x) boxplot
• xlabel(‘text')
• ylabel(‘text')
scatter(x,y,'d')
scatter(x,y,'*')
scatter(x,y,'b')
scatter(x,y,'p')
scatter(x,y,’+')
scatter(x,y,‘x')
theta = linspace(0,1,500);
x = exp(theta).*sin(100*theta);
y = exp(theta).*cos(100*theta);
s = scatter(x,y)
You may change color like scatter(x,y,’x’,’r’)
Regression…
load moore
y=moore(:,6)
x1=ones(length(y),1)
x2=moore(:,1:5)
x=[x1 x2]
% now perform regression %
[b,bint,r,rint,stats]=regress(y,x)
Test…
• %Single mean test
load stockreturns
x = stocks(:,3)
length(x)
[h,p,ci,stats] = ttest(x)
load stockreturns
x = stocks(:,3);
h = ttest(x,0,0.01)
• %paired mean test
load examgrades
x = grades(:,1);
y = grades(:,2);
[h,p] = ttest(x,y)
Cont…
%paired mean test
load examgrades
x = grades(:,1);
y = grades(:,2);
[h,p] = ttest2(x,y)
load examgrades
x = grades(:,1);
y = grades(:,2);
[h,p] = ttest(x,y,0.01)
Similar way F-test , z-test, chi-square test etc
%t-Test for a Hypothesized Mean
load examgrades
x = grades(:,1);
h = ttest(x,75)
%One-Sided t-Test
load examgrades
x = grades(:,1);
h = ttest(x,65,'right')
ANOVA…
% ANOVA one way
y = meshgrid(1:5);
y = y + normrnd(0,1,5,5)
p = anova1(y)
%ANOVA two way........
load popcorn
popcorn
[p,tbl] = anova2(popcorn,3);
Importing data…
• Excel data
• Watch the vedio
• File import data fix direcory
open ( tick generate matlab code) next
finish
https://www.youtube.com/watch?v=-
mZci3mNjlU
• clc clear commad window
• whos data size, class, bytes etc
• who provide variable names
• help mean
• help who
• help median
• help regression
• help plot
Thanks

More Related Content

What's hot

Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlabaman gupta
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABAshish Meshram
 
Basic matlab and matrix
Basic matlab and matrixBasic matlab and matrix
Basic matlab and matrixSaidur Rahman
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operatorsLuckshay Batra
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesShameer Ahmed Koya
 
Basics of matlab
Basics of matlabBasics of matlab
Basics of matlabAnil Maurya
 
Advanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsAdvanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsRay Phan
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Randa Elanwar
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkreddyprasad reddyvari
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabSantosh V
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABDamian T. Gordon
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabDnyanesh Patil
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab sessionDr. Krishna Mohbey
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to MatlabAmr Rashed
 
Matrix presentation By DHEERAJ KATARIA
Matrix presentation By DHEERAJ KATARIAMatrix presentation By DHEERAJ KATARIA
Matrix presentation By DHEERAJ KATARIADheeraj Kataria
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabBilawalBaloch1
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABBhavesh Shah
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab IntroductionDaniel Moore
 

What's hot (20)

Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Basic matlab and matrix
Basic matlab and matrixBasic matlab and matrix
Basic matlab and matrix
 
Matlab-Data types and operators
Matlab-Data types and operatorsMatlab-Data types and operators
Matlab-Data types and operators
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
 
Basics of matlab
Basics of matlabBasics of matlab
Basics of matlab
 
Advanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & ScientistsAdvanced MATLAB Tutorial for Engineers & Scientists
Advanced MATLAB Tutorial for Engineers & Scientists
 
Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4Introduction to matlab lecture 1 of 4
Introduction to matlab lecture 1 of 4
 
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulinkMATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
MATLAB/SIMULINK for Engineering Applications day 2:Introduction to simulink
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Fundamentals of matlab
Fundamentals of matlabFundamentals of matlab
Fundamentals of matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Matrix presentation By DHEERAJ KATARIA
Matrix presentation By DHEERAJ KATARIAMatrix presentation By DHEERAJ KATARIA
Matrix presentation By DHEERAJ KATARIA
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 

Similar to Introduction to matlab

Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functionsjoellivz
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersMurshida ck
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.pptnaveen_setty
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.pptaboma2hawi
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptxraghav415187
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introductionSatish Gummadi
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in spaceFaizan Shabbir
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programmingDamian T. Gordon
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxDevaraj Chilakala
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introductionssuser2797e4
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..Kamarudheen KV
 
mat lab introduction and basics to learn
mat lab introduction and basics to learnmat lab introduction and basics to learn
mat lab introduction and basics to learnpavan373
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.pptManasaChevula1
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.pptSudhirNayak43
 

Similar to Introduction to matlab (20)

Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
Matlab1
Matlab1Matlab1
Matlab1
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in space
 
bobok
bobokbobok
bobok
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 
Lec3
Lec3Lec3
Lec3
 
mat lab introduction and basics to learn
mat lab introduction and basics to learnmat lab introduction and basics to learn
mat lab introduction and basics to learn
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
 

More from Khulna University

Stat 2153 Introduction to Queiueng Theory
Stat 2153 Introduction to Queiueng TheoryStat 2153 Introduction to Queiueng Theory
Stat 2153 Introduction to Queiueng TheoryKhulna University
 
Stat 2153 Stochastic Process and Markov chain
Stat 2153 Stochastic Process and Markov chainStat 2153 Stochastic Process and Markov chain
Stat 2153 Stochastic Process and Markov chainKhulna University
 
Stat 3203 -sampling errors and non-sampling errors
Stat 3203 -sampling errors  and non-sampling errorsStat 3203 -sampling errors  and non-sampling errors
Stat 3203 -sampling errors and non-sampling errorsKhulna University
 
Stat 3203 -cluster and multi-stage sampling
Stat 3203 -cluster and multi-stage samplingStat 3203 -cluster and multi-stage sampling
Stat 3203 -cluster and multi-stage samplingKhulna University
 
Stat 3203 -multphase sampling
Stat 3203 -multphase samplingStat 3203 -multphase sampling
Stat 3203 -multphase samplingKhulna University
 
Stat 3203 -pps sampling
Stat 3203 -pps samplingStat 3203 -pps sampling
Stat 3203 -pps samplingKhulna University
 
Ds 2251 -_hypothesis test
Ds 2251 -_hypothesis testDs 2251 -_hypothesis test
Ds 2251 -_hypothesis testKhulna University
 
Stat 1163 -statistics in environmental science
Stat 1163 -statistics in environmental scienceStat 1163 -statistics in environmental science
Stat 1163 -statistics in environmental scienceKhulna University
 
Stat 1163 -correlation and regression
Stat 1163 -correlation and regressionStat 1163 -correlation and regression
Stat 1163 -correlation and regressionKhulna University
 
Different kind of distance and Statistical Distance
Different kind of distance and Statistical DistanceDifferent kind of distance and Statistical Distance
Different kind of distance and Statistical DistanceKhulna University
 
Regression and Classification: An Artificial Neural Network Approach
Regression and Classification: An Artificial Neural Network ApproachRegression and Classification: An Artificial Neural Network Approach
Regression and Classification: An Artificial Neural Network ApproachKhulna University
 

More from Khulna University (11)

Stat 2153 Introduction to Queiueng Theory
Stat 2153 Introduction to Queiueng TheoryStat 2153 Introduction to Queiueng Theory
Stat 2153 Introduction to Queiueng Theory
 
Stat 2153 Stochastic Process and Markov chain
Stat 2153 Stochastic Process and Markov chainStat 2153 Stochastic Process and Markov chain
Stat 2153 Stochastic Process and Markov chain
 
Stat 3203 -sampling errors and non-sampling errors
Stat 3203 -sampling errors  and non-sampling errorsStat 3203 -sampling errors  and non-sampling errors
Stat 3203 -sampling errors and non-sampling errors
 
Stat 3203 -cluster and multi-stage sampling
Stat 3203 -cluster and multi-stage samplingStat 3203 -cluster and multi-stage sampling
Stat 3203 -cluster and multi-stage sampling
 
Stat 3203 -multphase sampling
Stat 3203 -multphase samplingStat 3203 -multphase sampling
Stat 3203 -multphase sampling
 
Stat 3203 -pps sampling
Stat 3203 -pps samplingStat 3203 -pps sampling
Stat 3203 -pps sampling
 
Ds 2251 -_hypothesis test
Ds 2251 -_hypothesis testDs 2251 -_hypothesis test
Ds 2251 -_hypothesis test
 
Stat 1163 -statistics in environmental science
Stat 1163 -statistics in environmental scienceStat 1163 -statistics in environmental science
Stat 1163 -statistics in environmental science
 
Stat 1163 -correlation and regression
Stat 1163 -correlation and regressionStat 1163 -correlation and regression
Stat 1163 -correlation and regression
 
Different kind of distance and Statistical Distance
Different kind of distance and Statistical DistanceDifferent kind of distance and Statistical Distance
Different kind of distance and Statistical Distance
 
Regression and Classification: An Artificial Neural Network Approach
Regression and Classification: An Artificial Neural Network ApproachRegression and Classification: An Artificial Neural Network Approach
Regression and Classification: An Artificial Neural Network Approach
 

Recently uploaded

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 

Recently uploaded (20)

Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 

Introduction to matlab

  • 1. Introduction to MATLAB Md. Menhazul Abedin Lecturer, Statistics Discipline Khulna university menhaz70@gmail.com
  • 2. What is MATLAB • High level language for technical computing • Stands for MATrix LABoratory • Everything is a matrix - easy to do linear algebra
  • 3. MATLAB Desktop Menu and toolbar CommandHistory Workspace
  • 4. Valid variables Names • A valid variable name starts with a letter, followed by letters, digits, or underscores. • MATLABÂŽ is casesensitive, so A and a are not the same variable. • The maximum length of a variable name is the value that the namelengthmax command returns. • You cannot define variables with the same names as MATLAB keywords, such as if or end. For a complete list, run the iskeyword command.
  • 5. Matlab keywords…. • Keywords are must not variable name • 'break' 'case' 'catch' 'classdef' 'continue' 'else' 'elseif' 'end' 'for' 'function' 'global' 'if' 'otherwise' 'parfor' 'persistent' 'return' 'spmd' 'switch' 'try' 'while'
  • 6. How to run? • If program in command space press “ enter” • If in open script then block command and presss F9.
  • 7. Matrices & Vectors • All (almost) entities in MATLAB are matrices • Easy to define: • Use ‘,’ or ‘ ’ to separate row elements • use ‘;’ to separate rows >> A = [1 3; 5 8] A = 1 3 5 8 >> A = [1,3; 5,8] A = 1 3 5 8
  • 8. Matrices & Vectors • Order of Matrix - – m=no. of rows, – n=no. of columns • Vectors - special cases – n = 1 column vector – m = 1 row vector  m  n
  • 9. Simple algebraic operations Addition + Subtraction - Multiplication * Division / Power ^ Logarithm log() Exponential Exp() Square root sqrt() Absolute value abs()
  • 10. Element wise operations… .*element-by-element multiplication ./element-by-element division .^ element-by-element power
  • 11. Operators (relational, logical) • == Equal to • ~= Not equal to • < Strictly smaller • > Strictly greater • <= Smaller than or equal to • >= Greater than equal to • & And operator • | Or operator
  • 12. Sequences……. • t =1:10 t = 1 2 3 4 5 6 7 8 9 10 • k =2:-0.5:-1 k = 2 1.5 1 0.5 0 -0.5 -1 • y=[2:2:12] y= 2 4 6 8 10 12 • B = [1:4; 5:8] x = 1 2 3 4 5 6 7 8
  • 13. Some practice……. • Do some mathematical operations as like as calculator (addition, subtraction, multiplication, division, log, square root, power and so on)
  • 14. Matrix... • a vector x = [1 2 5 1] x = 1 2 5 1 • a matrix x = [1 2 3; 5 1 4; 3 2 -1] x = 1 2 3 5 1 4 3 2 -1
  • 15. Special matrix…. • Identity matrix= eye (row,column) • One matrix= ones(row,column) • Zero marix= zeros (row,column)
  • 16. Matrix operations… • Let A be a matrix…. • Determinant= det(A) • Transpose= A’ • Rank = rank(A) • Inverse= inv(A) • Trace = trace(A) • Eigen value=eig(A) • Eigen value and vector= [V,D] = eig(A) • Matrix multiplication= A*B • Matrix multiplication= A.*B [elementwise] • Singular values= svd(A)
  • 17. Cont… • diag diagonal atrix • triu upper triangular matrix • tril lower triangular matri • rand randomly generated matrix • C=rand(5,4) • triu(C) • tril(C) • diag([0.9092;0.5163;0.2661])
  • 18. Cont… • Length of a vector= length(x) • Size or dimension of matrix= size(A) • Replication of same number= repmat(number,m,n)
  • 19. Basic statistical building function… • Let be a sample • Mean= mean(x) • Median=median(x) • Mode= mode(x) • Variance=var(x) • Standard deviation=std(x) • Minimum= min(x) • Maximum= max(x) • Summation=sum(x) nxxxx ,...,, 21
  • 20. Data preprocessing…(Missing value) • a = magic(3); a(2,2) = NaN • a = 8 1 6 3 NaN 7 4 9 2 sum(a) ans = 15 NaN 15 sum(a) ans = 15 NaN 15 sum(a,'omitnan') ans = 15 10 15 Class of variables=class(A)
  • 21. Random number generation…. • Normal distribution: normrnd(mu,sigma) for a single value normrnd(mu,sigma,m,n) or normrnd(mu,sigma[m,n]) for matrix having m row and ncolumn • Poisson distribution: poissrnd(lamda) poissrnd(lamda,m,n) poissrnd(lamda,[m,n]) Binomial distribution: binornd(N,P) binornd(N,P,m,n) binornd(N,P,[m,n])
  • 22. Cont… • Geometric distribution: geornd(p) geornd(p,m,n) geornd(p,[m,n]) • Beta distribution: betarnd(A,B) betarnd(A,B,m,n) betarnd(A,B,[m,n]) Exponential distribution: exprnd(mu) exprnd(mu,m,n) exprnd(mu,[m,n]) Gamma distribution: gamrd(A,B) gamrnd(A,B,m,n) gamrnd(A,B,[m,n])
  • 23. Cont… • Standard normal distribution: randn return single value randn(n) return n-by-n square matrix randn(r,c) return r-by-c matrx
  • 24. Covariance of Matrix • C = cov(A,B) returns the covariance between two random variables A and B. • C = cov(A) returns the matrix of correlation coefficient for A, where the columns of A represent random variables and the rows represent observations.
  • 25. Example… • A = [5 0 3 7; 1 -5 7 3; 4 9 8 10]; C = cov(A) • A = [3 6 4]; B = [7 12 -9]; cov(A,B)
  • 26. Correlation coefficient… • R = corrcoef(A) returns the matrix of correlation coefficient for A, where the columns of A represent random variables and the rows represent observations. • R= corrcoef(A,B) returns coefficients between two random variables A and B.
  • 27. Example….. • x = randn(6,1); • y = randn(6,1); • A = [x y 2*y+3]; • R = corrcoef(A) • A = randn(10,1); • B = randn(10,1); • R = corrcoef(A,B)
  • 28. Ploting… • x vector • y vector • Z vector plot(x,y) 2D line diagram plot(x,y,z) 3D line diagram scatter(x,y) scatter diagram scatter(x,y,z) 3D scatter diagram bar(x) bar diagram bar3(x) 3D bar diagram hist(x) histogram boxplot(x) boxplot • xlabel(‘text') • ylabel(‘text') scatter(x,y,'d') scatter(x,y,'*') scatter(x,y,'b') scatter(x,y,'p') scatter(x,y,’+') scatter(x,y,‘x') theta = linspace(0,1,500); x = exp(theta).*sin(100*theta); y = exp(theta).*cos(100*theta); s = scatter(x,y) You may change color like scatter(x,y,’x’,’r’)
  • 29. Regression… load moore y=moore(:,6) x1=ones(length(y),1) x2=moore(:,1:5) x=[x1 x2] % now perform regression % [b,bint,r,rint,stats]=regress(y,x)
  • 30. Test… • %Single mean test load stockreturns x = stocks(:,3) length(x) [h,p,ci,stats] = ttest(x) load stockreturns x = stocks(:,3); h = ttest(x,0,0.01) • %paired mean test load examgrades x = grades(:,1); y = grades(:,2); [h,p] = ttest(x,y)
  • 31. Cont… %paired mean test load examgrades x = grades(:,1); y = grades(:,2); [h,p] = ttest2(x,y) load examgrades x = grades(:,1); y = grades(:,2); [h,p] = ttest(x,y,0.01) Similar way F-test , z-test, chi-square test etc %t-Test for a Hypothesized Mean load examgrades x = grades(:,1); h = ttest(x,75) %One-Sided t-Test load examgrades x = grades(:,1); h = ttest(x,65,'right')
  • 32. ANOVA… % ANOVA one way y = meshgrid(1:5); y = y + normrnd(0,1,5,5) p = anova1(y) %ANOVA two way........ load popcorn popcorn [p,tbl] = anova2(popcorn,3);
  • 33. Importing data… • Excel data • Watch the vedio • File import data fix direcory open ( tick generate matlab code) next finish https://www.youtube.com/watch?v=- mZci3mNjlU
  • 34. • clc clear commad window • whos data size, class, bytes etc • who provide variable names • help mean • help who • help median • help regression • help plot