SlideShare una empresa de Scribd logo
1 de 31
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

Más contenido relacionado

La actualidad más candente

Lesson 3 - matrix multiplication
Lesson 3 - matrix multiplicationLesson 3 - matrix multiplication
Lesson 3 - matrix multiplicationJonathan Templin
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introductionideas2ignite
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLABAshish Meshram
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingDr. Manjunatha. P
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arraysAmeen San
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlabaman gupta
 
Matlab m files and scripts
Matlab m files and scriptsMatlab m files and scripts
Matlab m files and scriptsAmeen San
 
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
 
Basic matlab and matrix
Basic matlab and matrixBasic matlab and matrix
Basic matlab and matrixSaidur Rahman
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlabkrajeshk1980
 
Matrix Manipulation in Matlab
Matrix Manipulation in MatlabMatrix Manipulation in Matlab
Matrix Manipulation in MatlabMohamed Loey
 
MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3reddyprasad reddyvari
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problemJayesh Chauhan
 
Taylor and Maclaurin Series
Taylor and Maclaurin SeriesTaylor and Maclaurin Series
Taylor and Maclaurin SeriesHarsh Pathak
 
Matrices and determinants
Matrices and determinantsMatrices and determinants
Matrices and determinantsoscar
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab sessionDr. Krishna Mohbey
 

La actualidad más candente (20)

Lesson 3 - matrix multiplication
Lesson 3 - matrix multiplicationLesson 3 - matrix multiplication
Lesson 3 - matrix multiplication
 
Matlab Introduction
Matlab IntroductionMatlab Introduction
Matlab Introduction
 
Seminar on MATLAB
Seminar on MATLABSeminar on MATLAB
Seminar on MATLAB
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Matlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processingMatlab for beginners, Introduction, signal processing
Matlab for beginners, Introduction, signal processing
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Matlab Script - Loop Control
Matlab Script - Loop ControlMatlab Script - Loop Control
Matlab Script - Loop Control
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Matlab m files and scripts
Matlab m files and scriptsMatlab m files and scripts
Matlab m files and scripts
 
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
 
Basic matlab and matrix
Basic matlab and matrixBasic matlab and matrix
Basic matlab and matrix
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
Matrix Manipulation in Matlab
Matrix Manipulation in MatlabMatrix Manipulation in Matlab
Matrix Manipulation in Matlab
 
MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3MATLAB/SIMULINK for engineering applications: day 3
MATLAB/SIMULINK for engineering applications: day 3
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problem
 
Taylor and Maclaurin Series
Taylor and Maclaurin SeriesTaylor and Maclaurin Series
Taylor and Maclaurin Series
 
Matrices and determinants
Matrices and determinantsMatrices and determinants
Matrices and determinants
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 

Similar a Introduction to matlab

Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdfssuser43b38e
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.pptkebeAman
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxDevaraj Chilakala
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functionsjoellivz
 
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 beyondMahuaPal6
 
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 .docxandreecapon
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd 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 projectsMukesh Kumar
 
INTRODUCTION TO MATLAB session with notes
  INTRODUCTION TO MATLAB   session with  notes  INTRODUCTION TO MATLAB   session with  notes
INTRODUCTION TO MATLAB session with notesInfinity Tech Solutions
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptxBeheraA
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 introRagu Nathan
 

Similar a 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 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
 
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
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 

Último

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Último (20)

Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

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