SlideShare a Scribd company logo
INTRODUCTION TO
MATLAB
By: Dnyandev Patil
[ MATRIX LABORATORY ]
Introduction to MATLAB
Side 1
OUTLINE: YOU WILL LEARN…
 What is MATLAB?
 MATLAB Screen
 Variables, array, matrix, indexing
 Operators (Arithmetic, relational, logical )
 Display Facilities
 Flow Control
 Using of M-File
 Conclusion
Introduction to MATLAB
Side 2
WHAT IS MATLAB?
 Matlab is basically a high level language which has many
specialized toolboxes for making things easier for us
 How high?
Assembly
High Level
Languages such as
C, Pascal etc.
Matlab
Introduction to MATLAB
Side 3
MATLAB SCREEN
Introduction to MATLAB
Side 4
VARIABLES
 No need for types. i.e.,
 All variables are created with double precision unless
specified and they are matrices.
 After these statements, the variables are 1x1 matrices
with double precision
int a;
double b;
float c;
Example:
>>x=5;
>>x1=2;
Introduction to MATLAB
Side 4
ARRAY, 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
 transpose y = x’ y =
1
2
5
1
Introduction to MATLAB
Side 5
LONG ARRAY, MATRIX
 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
 B = [1:4; 5:8]
B =
1 2 3 4
5 6 7 8
Introduction to MATLAB
Side 6
GENERATING VECTORS FROM FUNCTIONS
 zeros(M,N) MxN matrix of zeros
 ones(M,N) MxN matrix of ones
 rand(M,N) MxN matrix of uniformly
distributed random
numbers on (0,1)
x = zeros(1,3)
x =0 0 0
x = ones(1,3)
x =1 1 1
x = rand(1,3)
x=0.9501 0.2311 0.6068
Introduction to MATLAB
Side 7
MATRIX INDEX
 The matrix indices begin from 1 (not 0 (as in C))
 The matrix indices must be positive integer.
Given:
A(-2), A(0)
Error: ??? Subscript indices must either be real positive integers or logicals.
A(4,2)
Error: ??? Index exceeds matrix dimensions.
Introduction to MATLAB
Side 8
CONCATENATION OF MATRICES
 x = [1 2], y = [4 5], z=[ 0 0]
A = [ x y]
1 2 4 5
B = [x ; y]
1 2
4 5
C = [x y ;z]
Error:
??? Error using ==> vertcat CAT arguments dimensions are not consistent.
Introduction to MATLAB
Side 9
OPERATORS (ARITHMETIC)
+ addition
- subtraction
* multiplication
/ division
^ power
‘ complex conjugate transpose
Introduction to MATLAB
Side 10
MATRICES OPERATIONS
Given A and B:
Addition Subtraction Product Transpose
Introduction to MATLAB
Side 11
OPERATORS (ELEMENT BY ELEMENT)
.* element-by-element multiplication
./ element-by-element division
.^ element-by-element power
Introduction to MATLAB
Side 12
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
Introduction to MATLAB
Side 13
THE USE OF “ . ” – ELEMENT OPERATION
A = [1 2 3; 5 1 4; 3 2 1]
A =
1 2 3
5 1 4
3 2 -1
y = A(3 ,:)
y=
3 4 -1
b = x .* y
b=
3 8 -3
c = x . / y
c=
0.33 0.5 -3
d = x .^2
d=
1 4 9
x = A(1,:)
x=
1 2 3
Introduction to MATLAB
Side 14
PLOT THE FUNCTION SIN(X) BETWEEN 0≤ X
≤ 2Π
 Create an t-array of fraction 0.01,between 0 and 2π.
 Calculate sin of x
 Plot the x-array
>>t=0:0.01:2*pi;
>>x=5*sin(2*t);
>>plot(x)
0 100 200 300 400 500 600 700
-5
-4
-3
-2
-1
0
1
2
3
4
5
Introduction to MATLAB
Side 15
PLOT THE FUNCTION:
 Create an x-array of 100 samples between 0 and 4π.
 Calculate sin(.) of the x-array
 Calculate e-x/3 of the x-array
>>x=linspace (0,4*pi,100);
>>y=sin(x);
>>y1=exp(-x/3);
e-x/3sin(x) between 0≤x≤4π
Introduction to MATLAB
Side 16
PLOT THE FUNCTION E-X/3SIN(X)
BETWEEN 0≤X≤4Π
 Multiply the arrays y and y1 correctly
 Plot the y2-array
>>y2=y.*y1;
>>plot(y2)
0 10 20 30 40 50 60 70 80 90 100
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Introduction to MATLAB
Side 17
DISPLAY FACILITIES
 plot(.)
 stem(.)
Example:
x=linspace(0,4*pi,100);
y=sin(x);
y1=exp(-x/3);
y2=y.*y1;
plot(y2)
Example:
>>stem(y)
>>stem(x,y)
0 10 20 30 40 50 60 70 80 90 100
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0 10 20 30 40 50 60 70 80 90 100
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Introduction to MATLAB
Side 18
DISPLAY FACILITIES
 subplot(…)
x=linspace(0,4*pi,100);
y=sin(x);
y1=exp(-x/3);
y2=y.*y1;
subplot(121)
grid on
plot(y2)
title('plot function')
subplot(122)
grid on
stem(y2)
title(' stem function')
0 20 40 60 80 100
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
plot function
0 20 40 60 80 100
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
stem function
Introduction to MATLAB
Side 19
DISPLAY FACILITIES
 title(.)
 xlabel(.)
 ylabel(.)
>>title(‘This is the sinus function’)
>>xlabel(‘x (secs)’)
>>ylabel(‘sin(x)’) 0 10 20 30 40 50 60 70 80 90 100
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
This is the sinus function
x (secs)
sin(x)
Introduction to MATLAB
Side 20
FLOW CONTROL
 if
 for
 while
 break
 ….
Introduction to MATLAB
Side 21
CONTROL STRUCTURES
If Statement Syntax
if (Condition_1)
Matlab Commands
elseif (Condition_2)
Matlab Commands
elseif (Condition_3)
Matlab Commands
else
Matlab Commands
end
Examples:
if ((a>5) & (b==9))
Some Commands;
end
if (a<6)
Some Matlab Commands;
elseif (b=6)
Some Matlab Commands;
end
if (a=3)
Some Matlab Commands;
else
Some Matlab Commands;
end
Introduction to MATLAB
Side 22
CONTROL STRUCTURES
For loop syntax
for i=Index_Array
Matlab Commands
end
Some Dummy Examples
for i=1:100
Some Matlab Commands;
end
for j=1:3:200
Some Matlab Commands;
end
for m=13:-0.2:-21
Some Matlab Commands;
end
for k=[0.1 0.3 -13 12 7 -9.3]
Some Matlab Commands;
end
Introduction to MATLAB
Side 23
CONTROL STRUCTURES
 While Loop Syntax
while (condition)
Matlab Commands
end
Dummy Example:
while ((a>3) & (b==5))
Some Matlab Commands;
end
Introduction to MATLAB
Side 24
USE OF M-FILE
Click to create
a new M-File
Or New Script
• Extension “.m”
• A text file containing script or function or program to run
Introduction to MATLAB
Side 25
USE OF M-FILE
If you include “ ; ” at the
end of each statement,
result will not be displayed
In command window
Save file as file_name or file_name.m
Save and run
Introduction to MATLAB
Side 26
NOTES:
 “%” is the neglect sign for Matlab (equaivalent of “//” in C).
Anything after it on the same line is neglected by Matlab
compiler.
 Sometimes slowing down the execution is done
deliberately for observation purposes. You can use the
command “pause” for this purpose
pause %wait until any key
pause(3) %wait 3 seconds
Introduction to MATLAB
Side 27
USEFUL COMMANDS
 The two commands used most by Matlab
users are
>>help functionname
>>lookfor keyword
Introduction to MATLAB
Side 28
QUESTIONS
 ?
 ?
 ?
 ?
 ?
Introduction to MATLAB
Side 29
THANK YOU…
Introduction to MATLAB
Side 30

More Related Content

What's hot

MATLAB INTRODUCTION
MATLAB INTRODUCTIONMATLAB INTRODUCTION
MATLAB INTRODUCTION
Dr. Krishna Mohbey
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
Daniel Moore
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Ameen San
 
How to work on Matlab.......
How to work on Matlab.......How to work on Matlab.......
How to work on Matlab.......biinoida
 
Matlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IMatlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - I
Vijay Kumar Gupta
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab sessionDr. Krishna Mohbey
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
ideas2ignite
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabSantosh V
 
Matlab introduction lecture 1
Matlab introduction lecture 1Matlab introduction lecture 1
Matlab introduction lecture 1
Mohamed Awni
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processing
Dr. Manjunatha. P
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Mohan Raj
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1
Elaf A.Saeed
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
Introduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdfIntroduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdf
DrAzizulHasan1
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
Murshida ck
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Bhavesh Shah
 
ADVANCED COMPUTER ARCHITECTURE PARALLELISM SCALABILITY PROGRAMMABILITY Baas ...
ADVANCED COMPUTER ARCHITECTURE PARALLELISM SCALABILITY PROGRAMMABILITY Baas  ...ADVANCED COMPUTER ARCHITECTURE PARALLELISM SCALABILITY PROGRAMMABILITY Baas  ...
ADVANCED COMPUTER ARCHITECTURE PARALLELISM SCALABILITY PROGRAMMABILITY Baas ...
Angie Miller
 
Matlab
MatlabMatlab
Matlab
sandhya jois
 

What's hot (20)

MATLAB INTRODUCTION
MATLAB INTRODUCTIONMATLAB INTRODUCTION
MATLAB INTRODUCTION
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
How to work on Matlab.......
How to work on Matlab.......How to work on Matlab.......
How to work on Matlab.......
 
Matlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - IMatlab Tutorial for Beginners - I
Matlab Tutorial for Beginners - I
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab introduction lecture 1
Matlab introduction lecture 1Matlab introduction lecture 1
Matlab introduction lecture 1
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processing
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Realibity design
Realibity designRealibity design
Realibity design
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
 
Introduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdfIntroduction to Matlab for Engineering Students.pdf
Introduction to Matlab for Engineering Students.pdf
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
ADVANCED COMPUTER ARCHITECTURE PARALLELISM SCALABILITY PROGRAMMABILITY Baas ...
ADVANCED COMPUTER ARCHITECTURE PARALLELISM SCALABILITY PROGRAMMABILITY Baas  ...ADVANCED COMPUTER ARCHITECTURE PARALLELISM SCALABILITY PROGRAMMABILITY Baas  ...
ADVANCED COMPUTER ARCHITECTURE PARALLELISM SCALABILITY PROGRAMMABILITY Baas ...
 
Matlab
MatlabMatlab
Matlab
 

Similar to Introduction to matlab

Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdf
ssuser43b38e
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
kebeAman
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
raghav415187
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
BilawalBaloch1
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
Devaraj Chilakala
 
Programming with matlab session 1
Programming with matlab session 1Programming with matlab session 1
Programming with matlab session 1
Infinity Tech Solutions
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Vikash Jakhar
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
joellivz
 
Matlab
MatlabMatlab
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
MahuaPal6
 
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxMATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
andreecapon
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
Mohd Esa
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
Mukesh Kumar
 
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
reddyprasad reddyvari
 
INTRODUCTION TO MATLAB session with notes
  INTRODUCTION TO MATLAB   session with  notes  INTRODUCTION TO MATLAB   session with  notes
INTRODUCTION TO MATLAB session with notes
Infinity Tech Solutions
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx
BeheraA
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 intro
Ragu Nathan
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
Ravibabu Kancharla
 

Similar to Introduction to matlab (20)

Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdf
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
 
Programming with matlab session 1
Programming with matlab session 1Programming with matlab session 1
Programming with matlab session 1
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab1
Matlab1Matlab1
Matlab1
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
Matlab booklet
Matlab bookletMatlab booklet
Matlab booklet
 
Matlab
MatlabMatlab
Matlab
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
 
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxMATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
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 session with notes
  INTRODUCTION TO MATLAB   session with  notes  INTRODUCTION TO MATLAB   session with  notes
INTRODUCTION TO MATLAB session with notes
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 intro
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 

Introduction to matlab

  • 1. INTRODUCTION TO MATLAB By: Dnyandev Patil [ MATRIX LABORATORY ] Introduction to MATLAB Side 1
  • 2. OUTLINE: YOU WILL LEARN…  What is MATLAB?  MATLAB Screen  Variables, array, matrix, indexing  Operators (Arithmetic, relational, logical )  Display Facilities  Flow Control  Using of M-File  Conclusion Introduction to MATLAB Side 2
  • 3. WHAT IS MATLAB?  Matlab is basically a high level language which has many specialized toolboxes for making things easier for us  How high? Assembly High Level Languages such as C, Pascal etc. Matlab Introduction to MATLAB Side 3
  • 5. VARIABLES  No need for types. i.e.,  All variables are created with double precision unless specified and they are matrices.  After these statements, the variables are 1x1 matrices with double precision int a; double b; float c; Example: >>x=5; >>x1=2; Introduction to MATLAB Side 4
  • 6. ARRAY, 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  transpose y = x’ y = 1 2 5 1 Introduction to MATLAB Side 5
  • 7. LONG ARRAY, MATRIX  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  B = [1:4; 5:8] B = 1 2 3 4 5 6 7 8 Introduction to MATLAB Side 6
  • 8. GENERATING VECTORS FROM FUNCTIONS  zeros(M,N) MxN matrix of zeros  ones(M,N) MxN matrix of ones  rand(M,N) MxN matrix of uniformly distributed random numbers on (0,1) x = zeros(1,3) x =0 0 0 x = ones(1,3) x =1 1 1 x = rand(1,3) x=0.9501 0.2311 0.6068 Introduction to MATLAB Side 7
  • 9. MATRIX INDEX  The matrix indices begin from 1 (not 0 (as in C))  The matrix indices must be positive integer. Given: A(-2), A(0) Error: ??? Subscript indices must either be real positive integers or logicals. A(4,2) Error: ??? Index exceeds matrix dimensions. Introduction to MATLAB Side 8
  • 10. CONCATENATION OF MATRICES  x = [1 2], y = [4 5], z=[ 0 0] A = [ x y] 1 2 4 5 B = [x ; y] 1 2 4 5 C = [x y ;z] Error: ??? Error using ==> vertcat CAT arguments dimensions are not consistent. Introduction to MATLAB Side 9
  • 11. OPERATORS (ARITHMETIC) + addition - subtraction * multiplication / division ^ power ‘ complex conjugate transpose Introduction to MATLAB Side 10
  • 12. MATRICES OPERATIONS Given A and B: Addition Subtraction Product Transpose Introduction to MATLAB Side 11
  • 13. OPERATORS (ELEMENT BY ELEMENT) .* element-by-element multiplication ./ element-by-element division .^ element-by-element power Introduction to MATLAB Side 12
  • 14. 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 Introduction to MATLAB Side 13
  • 15. THE USE OF “ . ” – ELEMENT OPERATION A = [1 2 3; 5 1 4; 3 2 1] A = 1 2 3 5 1 4 3 2 -1 y = A(3 ,:) y= 3 4 -1 b = x .* y b= 3 8 -3 c = x . / y c= 0.33 0.5 -3 d = x .^2 d= 1 4 9 x = A(1,:) x= 1 2 3 Introduction to MATLAB Side 14
  • 16. PLOT THE FUNCTION SIN(X) BETWEEN 0≤ X ≤ 2Π  Create an t-array of fraction 0.01,between 0 and 2π.  Calculate sin of x  Plot the x-array >>t=0:0.01:2*pi; >>x=5*sin(2*t); >>plot(x) 0 100 200 300 400 500 600 700 -5 -4 -3 -2 -1 0 1 2 3 4 5 Introduction to MATLAB Side 15
  • 17. PLOT THE FUNCTION:  Create an x-array of 100 samples between 0 and 4π.  Calculate sin(.) of the x-array  Calculate e-x/3 of the x-array >>x=linspace (0,4*pi,100); >>y=sin(x); >>y1=exp(-x/3); e-x/3sin(x) between 0≤x≤4π Introduction to MATLAB Side 16
  • 18. PLOT THE FUNCTION E-X/3SIN(X) BETWEEN 0≤X≤4Π  Multiply the arrays y and y1 correctly  Plot the y2-array >>y2=y.*y1; >>plot(y2) 0 10 20 30 40 50 60 70 80 90 100 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 Introduction to MATLAB Side 17
  • 19. DISPLAY FACILITIES  plot(.)  stem(.) Example: x=linspace(0,4*pi,100); y=sin(x); y1=exp(-x/3); y2=y.*y1; plot(y2) Example: >>stem(y) >>stem(x,y) 0 10 20 30 40 50 60 70 80 90 100 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0 10 20 30 40 50 60 70 80 90 100 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 Introduction to MATLAB Side 18
  • 20. DISPLAY FACILITIES  subplot(…) x=linspace(0,4*pi,100); y=sin(x); y1=exp(-x/3); y2=y.*y1; subplot(121) grid on plot(y2) title('plot function') subplot(122) grid on stem(y2) title(' stem function') 0 20 40 60 80 100 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 plot function 0 20 40 60 80 100 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 stem function Introduction to MATLAB Side 19
  • 21. DISPLAY FACILITIES  title(.)  xlabel(.)  ylabel(.) >>title(‘This is the sinus function’) >>xlabel(‘x (secs)’) >>ylabel(‘sin(x)’) 0 10 20 30 40 50 60 70 80 90 100 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1 This is the sinus function x (secs) sin(x) Introduction to MATLAB Side 20
  • 22. FLOW CONTROL  if  for  while  break  …. Introduction to MATLAB Side 21
  • 23. CONTROL STRUCTURES If Statement Syntax if (Condition_1) Matlab Commands elseif (Condition_2) Matlab Commands elseif (Condition_3) Matlab Commands else Matlab Commands end Examples: if ((a>5) & (b==9)) Some Commands; end if (a<6) Some Matlab Commands; elseif (b=6) Some Matlab Commands; end if (a=3) Some Matlab Commands; else Some Matlab Commands; end Introduction to MATLAB Side 22
  • 24. CONTROL STRUCTURES For loop syntax for i=Index_Array Matlab Commands end Some Dummy Examples for i=1:100 Some Matlab Commands; end for j=1:3:200 Some Matlab Commands; end for m=13:-0.2:-21 Some Matlab Commands; end for k=[0.1 0.3 -13 12 7 -9.3] Some Matlab Commands; end Introduction to MATLAB Side 23
  • 25. CONTROL STRUCTURES  While Loop Syntax while (condition) Matlab Commands end Dummy Example: while ((a>3) & (b==5)) Some Matlab Commands; end Introduction to MATLAB Side 24
  • 26. USE OF M-FILE Click to create a new M-File Or New Script • Extension “.m” • A text file containing script or function or program to run Introduction to MATLAB Side 25
  • 27. USE OF M-FILE If you include “ ; ” at the end of each statement, result will not be displayed In command window Save file as file_name or file_name.m Save and run Introduction to MATLAB Side 26
  • 28. NOTES:  “%” is the neglect sign for Matlab (equaivalent of “//” in C). Anything after it on the same line is neglected by Matlab compiler.  Sometimes slowing down the execution is done deliberately for observation purposes. You can use the command “pause” for this purpose pause %wait until any key pause(3) %wait 3 seconds Introduction to MATLAB Side 27
  • 29. USEFUL COMMANDS  The two commands used most by Matlab users are >>help functionname >>lookfor keyword Introduction to MATLAB Side 28
  • 30. QUESTIONS  ?  ?  ?  ?  ? Introduction to MATLAB Side 29