SlideShare a Scribd company logo
1 of 28
COMPANION
TO MATRICES
BY
R.IMMANUAL
Certified on MATLAB
Onramp by Math works
Training services(MATLAB
Academy)
About this Session
• We will coverthe following
topics
•Loops and Execution Control
•MATLAB files: Scripts and Functions
•Program Output and Plotting
Loops & control execution
 For loop :Repeat statements a specific number of
times.
for i=1:10
<statement 1>;
⋮
<statement n>;
end
Loops & control execution
• While Loop (commands below will execute if the
condition is true)
while i<10
<statement 1>;
⋮
<statement n>; i=i+1;
end
Switch statement
switch Switch among several cases based on expression.
The general form of the switch statement is:
switch switch_expr
CASE case_expr,
statement, ..., statement
CASE {case_expr1, case_expr2, case_expr3,...}
statement, ..., statement
...
OTHERWISE,
statement, ..., statement
END
Practical Task 01
 When dhoni hits a ball at
an initial velocity of
20m/s. Find the location
of ball in every 0.1
seconds.
Find the position for first 10 seconds
v0=20;
g=9.81;
y=0;
t=0;
time=[];
location=[];
for t = 0:0.1:10
disp(['at time ',num2str(t),'location of the ball at the v
distance',num2str(y)]);
y=(v0*t)-0.5*g*t^2;
time=[t;time];
location=[location;y];
end
plot(time,location);
Practical Task 02
 When dhoni hits a ball at
an initial velocity of
20m/s. Find the location
of ball in every 0.1
seconds.
Find the position while the position not equal to zero
(upto reaches the ground)
v0=20;
g=9.81;
y=0;
t=0;
time=0;
location=0;
while y>=0
disp(['at time ',num2str(t),'location of the ball at the distance',num2str(y)]);
t=t+0.1;
y=(v0*t)-0.5*g*t^2;
time=[time;t];
location=[location;y];
end
plot(time,location,'--r');
Ouputs
disp Display array.
disp(X) displays array X without printing the array name
or
additional description information such as the size and
class name.
In all other ways it's the same as leaving the semicolon
off an
expression except that nothing is shown for empty
arrays.
If X is a string or character array, the text is displayed.
num2str Convert numbers to character
representation
T = num2str(X) converts the matrix X into its
character representation T
with about 4 digits and an exponent if
required. This is useful for
labeling plots with the TITLE, XLABEL,
YLABEL, and TEXT commands.
Plotting
plot Linear plot.
 plot(X,Y) plots vector Y versus vector X. If X
or Y is a matrix, then the vector is plotted
versus the rows or columns of the matrix,
whichever line up. If X is a scalar and Y is a
vector, disconnected line objects are created
and plotted as discrete points vertically at X.
 Various line types, plot symbols and colors
may be obtained with plot(X,Y,S) where S is
a character string made from one element
from any or all the following 3 columns:
b blue . point - solid
g green o circle : dotted
r red x x-mark -. dashdot
c cyan + plus -- dashed
m magenta * star (none) no line
y yellow s square
k black d diamond
w white v triangle (down)
^ triangle (up)
< triangle (left)
> triangle (right)
p pentagram
h hexagram
 For example, plot(X,Y,'c+:') plots a cyan dotted
line with a plus at each data point; plot(X,Y,'bd')
plots blue diamond at each data point but does
not draw any line.
 plot(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines
the plots defined by the (X,Y,S) triples, where the
X's and Y's are vectors or matrices and the S's
are strings.

Task 01
 Try creating a plot with sample on the x-axis
and mass1on the y-axis.
Task 02
 Try plotting mass2 (y-axis) against sample (x-
axis). Use red (r) star (*) markers and no line
in your plot.
plot(x,y,'r--o')
The command above plots a red (r) dashed (--)
line with a circle (o) as a marker. You can learn
more about the symbols available in the
documentation for Line Specification.
Task 03
 Info: Notice that the first plot you created no
longer exists. To plot one line on top of
another, use the holdon command to hold the
previous plot while you add another line. You
can also use the hold offcommand to return to
the default behavior.
 Issue the hold on command.
Task 04
 Now, plot mass1 (y-axis) against sample (x-
axis) with black (k) square (s) markers and no
line. (Line specification options)
Task 05
 Try closing all open figure windows by issuing
the closeall command.
Task 06
 Info: The plot function accepts optional
additional inputs consisting of a property
name and an associated value.
>> plot(y,'LineWidth',5)
The command above plots a heavy line. You
can learn more about available properties in
the documentation for Lineseries Properties.
 Now try plotting v1 with a line width of 3.
Task 07
 Info: The plot function accepts a property
name and property value pair after the plotted
arguments and line specifier.
 plot(x,y,'ro-','LineWidth',5)
 Try plotting v1 (y-axis) against sample (x-axis)
with red (r) circle (o) markers with a line width
of 4.
Task 08
 Info: Labels can be added to plots using plot
annotation functions, such as title. The input
to these functions is a string. Strings in
MATLAB are enclosed in single quotes (').
>> title('Plot Title')
 Try adding the title 'Sample Densities' to the
existing plot.
Task 09
 Use the ylabel function to add the
label 'Density (g/cm^3)'.
Task 10
 Create legend
 legend(string1,string2,string3, ...) puts a
legend on the current plot
Plotting Tab
3D graphics using the
functions surf, plot3 or mesh.
[X,Y] = meshgrid(-10:0.25:10,-10:0.25:10);
f = sinc(sqrt((X/pi).^2+(Y/pi).^2)); mesh(X,Y,f);
axis([-10 10 -10 10 -0.3 1])
xlabel('{bfx}')
ylabel('{bfy}')
zlabel('{bfsinc} ({bfR})')
hidden off
COMPANION TO MATRICES SESSION III.pptx

More Related Content

Similar to COMPANION TO MATRICES SESSION III.pptx

matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.pptnaveen_setty
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.pptaboma2hawi
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxDevaraj Chilakala
 
1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptxSungaleliYuen
 
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
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptximman gwu
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Philip Schwarz
 
Advanced matlab codigos matematicos
Advanced matlab codigos matematicosAdvanced matlab codigos matematicos
Advanced matlab codigos matematicosKmilo Bolaños
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functionsjoellivz
 

Similar to COMPANION TO MATRICES SESSION III.pptx (20)

matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
 
1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptx
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptx
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1
 
Mat lab
Mat labMat lab
Mat lab
 
Advanced matlab codigos matematicos
Advanced matlab codigos matematicosAdvanced matlab codigos matematicos
Advanced matlab codigos matematicos
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
Line Detection
Line DetectionLine Detection
Line Detection
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
R lecture co4_math 21-1
R lecture co4_math 21-1R lecture co4_math 21-1
R lecture co4_math 21-1
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 

More from imman gwu

DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATION
DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATIONDSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATION
DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATIONimman gwu
 
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDY
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDYINTERNET OF THINGS DEFINITION APPLICATION CASE STUDY
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDYimman gwu
 
UAV CATEGORIES CLASSIFICATION, TYPES USES
UAV CATEGORIES CLASSIFICATION, TYPES USESUAV CATEGORIES CLASSIFICATION, TYPES USES
UAV CATEGORIES CLASSIFICATION, TYPES USESimman gwu
 
GWU_DRONE AND AI HOW DRONE AND AI RELATED
GWU_DRONE AND AI HOW DRONE AND AI RELATEDGWU_DRONE AND AI HOW DRONE AND AI RELATED
GWU_DRONE AND AI HOW DRONE AND AI RELATEDimman gwu
 
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHT
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHTDRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHT
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHTimman gwu
 
COMPANION TO MATRICES SESSION IV.pptx
COMPANION TO MATRICES SESSION IV.pptxCOMPANION TO MATRICES SESSION IV.pptx
COMPANION TO MATRICES SESSION IV.pptximman gwu
 
COMPANION TO MATRICES SESSION I.pptx
COMPANION TO MATRICES SESSION I.pptxCOMPANION TO MATRICES SESSION I.pptx
COMPANION TO MATRICES SESSION I.pptximman gwu
 
imman resume final
imman resume finalimman resume final
imman resume finalimman gwu
 

More from imman gwu (8)

DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATION
DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATIONDSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATION
DSCE_GWU_3D PRINTING TYPES APPLICATIONS APPLICATION
 
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDY
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDYINTERNET OF THINGS DEFINITION APPLICATION CASE STUDY
INTERNET OF THINGS DEFINITION APPLICATION CASE STUDY
 
UAV CATEGORIES CLASSIFICATION, TYPES USES
UAV CATEGORIES CLASSIFICATION, TYPES USESUAV CATEGORIES CLASSIFICATION, TYPES USES
UAV CATEGORIES CLASSIFICATION, TYPES USES
 
GWU_DRONE AND AI HOW DRONE AND AI RELATED
GWU_DRONE AND AI HOW DRONE AND AI RELATEDGWU_DRONE AND AI HOW DRONE AND AI RELATED
GWU_DRONE AND AI HOW DRONE AND AI RELATED
 
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHT
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHTDRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHT
DRONE PRINCIPLES BASIC PRINCIPLE OF FLIGHT
 
COMPANION TO MATRICES SESSION IV.pptx
COMPANION TO MATRICES SESSION IV.pptxCOMPANION TO MATRICES SESSION IV.pptx
COMPANION TO MATRICES SESSION IV.pptx
 
COMPANION TO MATRICES SESSION I.pptx
COMPANION TO MATRICES SESSION I.pptxCOMPANION TO MATRICES SESSION I.pptx
COMPANION TO MATRICES SESSION I.pptx
 
imman resume final
imman resume finalimman resume final
imman resume final
 

Recently uploaded

Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086anil_gaur
 

Recently uploaded (20)

Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 

COMPANION TO MATRICES SESSION III.pptx

  • 1. COMPANION TO MATRICES BY R.IMMANUAL Certified on MATLAB Onramp by Math works Training services(MATLAB Academy)
  • 2. About this Session • We will coverthe following topics •Loops and Execution Control •MATLAB files: Scripts and Functions •Program Output and Plotting
  • 3. Loops & control execution  For loop :Repeat statements a specific number of times. for i=1:10 <statement 1>; ⋮ <statement n>; end
  • 4. Loops & control execution • While Loop (commands below will execute if the condition is true) while i<10 <statement 1>; ⋮ <statement n>; i=i+1; end
  • 5. Switch statement switch Switch among several cases based on expression. The general form of the switch statement is: switch switch_expr CASE case_expr, statement, ..., statement CASE {case_expr1, case_expr2, case_expr3,...} statement, ..., statement ... OTHERWISE, statement, ..., statement END
  • 6. Practical Task 01  When dhoni hits a ball at an initial velocity of 20m/s. Find the location of ball in every 0.1 seconds. Find the position for first 10 seconds
  • 7. v0=20; g=9.81; y=0; t=0; time=[]; location=[]; for t = 0:0.1:10 disp(['at time ',num2str(t),'location of the ball at the v distance',num2str(y)]); y=(v0*t)-0.5*g*t^2; time=[t;time]; location=[location;y]; end plot(time,location);
  • 8. Practical Task 02  When dhoni hits a ball at an initial velocity of 20m/s. Find the location of ball in every 0.1 seconds. Find the position while the position not equal to zero (upto reaches the ground)
  • 9. v0=20; g=9.81; y=0; t=0; time=0; location=0; while y>=0 disp(['at time ',num2str(t),'location of the ball at the distance',num2str(y)]); t=t+0.1; y=(v0*t)-0.5*g*t^2; time=[time;t]; location=[location;y]; end plot(time,location,'--r');
  • 10. Ouputs disp Display array. disp(X) displays array X without printing the array name or additional description information such as the size and class name. In all other ways it's the same as leaving the semicolon off an expression except that nothing is shown for empty arrays. If X is a string or character array, the text is displayed.
  • 11. num2str Convert numbers to character representation T = num2str(X) converts the matrix X into its character representation T with about 4 digits and an exponent if required. This is useful for labeling plots with the TITLE, XLABEL, YLABEL, and TEXT commands.
  • 12. Plotting plot Linear plot.  plot(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, disconnected line objects are created and plotted as discrete points vertically at X.
  • 13.  Various line types, plot symbols and colors may be obtained with plot(X,Y,S) where S is a character string made from one element from any or all the following 3 columns:
  • 14. b blue . point - solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus -- dashed m magenta * star (none) no line y yellow s square k black d diamond w white v triangle (down) ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram
  • 15.  For example, plot(X,Y,'c+:') plots a cyan dotted line with a plus at each data point; plot(X,Y,'bd') plots blue diamond at each data point but does not draw any line.  plot(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by the (X,Y,S) triples, where the X's and Y's are vectors or matrices and the S's are strings. 
  • 16. Task 01  Try creating a plot with sample on the x-axis and mass1on the y-axis.
  • 17. Task 02  Try plotting mass2 (y-axis) against sample (x- axis). Use red (r) star (*) markers and no line in your plot. plot(x,y,'r--o') The command above plots a red (r) dashed (--) line with a circle (o) as a marker. You can learn more about the symbols available in the documentation for Line Specification.
  • 18. Task 03  Info: Notice that the first plot you created no longer exists. To plot one line on top of another, use the holdon command to hold the previous plot while you add another line. You can also use the hold offcommand to return to the default behavior.  Issue the hold on command.
  • 19. Task 04  Now, plot mass1 (y-axis) against sample (x- axis) with black (k) square (s) markers and no line. (Line specification options)
  • 20. Task 05  Try closing all open figure windows by issuing the closeall command.
  • 21. Task 06  Info: The plot function accepts optional additional inputs consisting of a property name and an associated value. >> plot(y,'LineWidth',5) The command above plots a heavy line. You can learn more about available properties in the documentation for Lineseries Properties.  Now try plotting v1 with a line width of 3.
  • 22. Task 07  Info: The plot function accepts a property name and property value pair after the plotted arguments and line specifier.  plot(x,y,'ro-','LineWidth',5)  Try plotting v1 (y-axis) against sample (x-axis) with red (r) circle (o) markers with a line width of 4.
  • 23. Task 08  Info: Labels can be added to plots using plot annotation functions, such as title. The input to these functions is a string. Strings in MATLAB are enclosed in single quotes ('). >> title('Plot Title')  Try adding the title 'Sample Densities' to the existing plot.
  • 24. Task 09  Use the ylabel function to add the label 'Density (g/cm^3)'.
  • 25. Task 10  Create legend  legend(string1,string2,string3, ...) puts a legend on the current plot
  • 27. 3D graphics using the functions surf, plot3 or mesh. [X,Y] = meshgrid(-10:0.25:10,-10:0.25:10); f = sinc(sqrt((X/pi).^2+(Y/pi).^2)); mesh(X,Y,f); axis([-10 10 -10 10 -0.3 1]) xlabel('{bfx}') ylabel('{bfy}') zlabel('{bfsinc} ({bfR})') hidden off