SlideShare a Scribd company logo
1 of 10
Download to read offline
Ashoka bairwa
MATLAB ASHOK(191890)
Practical—3
Theory: A loop is a set of instructions that is repeated until a given condition is met in computer science. Loops are
used by programmers to repeat the task using values, add numbers, repeat functions, etc. The majority of modern
programming languages support loops, though their implementations. But their syntax may differ.
A. Types of Loop: three of the most common types of loop--------
• While loops
• for loops
• nested loops
▪ There may be a situation when you need to execute a block of code several times. In general, statements are
executed sequentially. The first statement in a function is executed first, followed by the second, and so on.
▪ Programming languages provide various control structures that allow for more complicated execution paths.
▪ A loop statement allows us to execute a statement or group of statements multiple times. The drawing shows the
general form of a loop statement for most programming languages.
▪ Matlab provides various types of loops to handle looping requirements including: while loops, for loops, and
nested loops. If you are trying to declare or write your own loops, you need to make sure that the loops are
written as scripts and not directly in the Command Window
Ashoka bairwa
MATLAB ASHOK(191890)
1)While Loop:
The while loop repeatedly executes statements while a specified condition is true.
• The syntax of a while loop in MATLAB is as following:
While<expression>
<statement>
end
Ashoka bairwa
MATLAB ASHOK(191890)
2)For loop
A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a
specific number of times.
The syntax of a for loop in MATLAB is as following:
For index=values
<programstatement>
……
end
Ashoka bairwa
MATLAB ASHOK(191890)
Ashoka bairwa
MATLAB ASHOK(191890)
3)The Nested Loops:
Matlab also allows to use one loop inside another loop.
The syntax for a nested for loop statement in MATLAB is as follows:
For m=i:j
Forn=i:j
<statement>;
end
end
or
while <expression 1>
while <expression 2>
<statement>
end
end
Ashoka bairwa
MATLAB ASHOK(191890)
Ashoka bairwa
MATLAB ASHOK(191890)
Loop Control Statements :
❖ Loop control statements change execution from its normal sequence.
❖ When execution leaves a scope, all automatic objects that were created in that scope are destroyed.
❖ The scope defines where the variables can be valid in Matlab, typically a scope within a loop body
is from the beginning of conditional code to the end of conditional code.
❖ It tells Matlab what to do when the conditional code fails in the loop. Matlab supports both break
statement and continue statement.
There are three case in loop control:
▪ Break
▪ Continue
▪ Switch
Ashoka bairwa
MATLAB ASHOK(191890)
Break statement.
❖ The break statement terminates execution of for or while loops. Statements in the loop that appear after the
break statement are not executed.
❖ In nested loops, break exits only from the loop in which it occurs. Control passes to the statement following the
end of that loop.
Ashoka bairwa
MATLAB ASHOK(191890)
Continue Statement:
❖ The continue statement is used for passing control to thenext iteration of a for or while loop.
❖ The continue statement in MATLAB works somewhat like the break statement. Instead of forcing
termination, however, 'continue' forces the next iteration of the loop to take place, skipping any code in
between.
Ashoka bairwa
MATLAB ASHOK(191890)
Switch Statement:
A switch statement help us choose one among a number of option using code that is easier.
I
Syntax of Switch Statement in Matlab
switch
switch_condition
case case_condition
statements_if_true
case case_condition
statements_if_true
...
Otherwise_condition
Statements_if_true
end
end……

More Related Content

Similar to Matlab practical ---3.pdf

Instrumentation and measurements
Instrumentation and measurementsInstrumentation and measurements
Instrumentation and measurementsTuba Tanveer
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scriptingAmirul Shafeeq
 
Matlab - Introduction and Basics
Matlab - Introduction and BasicsMatlab - Introduction and Basics
Matlab - Introduction and BasicsTechsparks
 
Cpp loop types
Cpp loop typesCpp loop types
Cpp loop typesRj Baculo
 
prt123.pptx
prt123.pptxprt123.pptx
prt123.pptxASADKS
 
Programming Sessions KU Leuven - Session 03
Programming Sessions KU Leuven - Session 03Programming Sessions KU Leuven - Session 03
Programming Sessions KU Leuven - Session 03Rafael Camacho Dejay
 
Matlab for diploma students(1)
Matlab for diploma students(1)Matlab for diploma students(1)
Matlab for diploma students(1)Retheesh Raj
 
Chapter 3 - Flow of Control Part II.pdf
Chapter 3  - Flow of Control Part II.pdfChapter 3  - Flow of Control Part II.pdf
Chapter 3 - Flow of Control Part II.pdfKirubelWondwoson1
 
Cse lecture-7-c loop
Cse lecture-7-c loopCse lecture-7-c loop
Cse lecture-7-c loopFarshidKhan
 
Introduction_to_Matlab_lecture.pptx
Introduction_to_Matlab_lecture.pptxIntroduction_to_Matlab_lecture.pptx
Introduction_to_Matlab_lecture.pptxaboma2hawi
 
plsql tutorialhub....
plsql tutorialhub....plsql tutorialhub....
plsql tutorialhub....Abhiram Vijay
 
Introduction to programming in MATLAB
Introduction to programming in MATLABIntroduction to programming in MATLAB
Introduction to programming in MATLABmustafa_92
 

Similar to Matlab practical ---3.pdf (20)

Arduino Functions
Arduino FunctionsArduino Functions
Arduino Functions
 
Matlab guide
Matlab guideMatlab guide
Matlab guide
 
Instrumentation and measurements
Instrumentation and measurementsInstrumentation and measurements
Instrumentation and measurements
 
EE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manualEE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manual
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
 
Matopt
MatoptMatopt
Matopt
 
Matlab - Introduction and Basics
Matlab - Introduction and BasicsMatlab - Introduction and Basics
Matlab - Introduction and Basics
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
 
Cpp loop types
Cpp loop typesCpp loop types
Cpp loop types
 
prt123.pptx
prt123.pptxprt123.pptx
prt123.pptx
 
Programming Sessions KU Leuven - Session 03
Programming Sessions KU Leuven - Session 03Programming Sessions KU Leuven - Session 03
Programming Sessions KU Leuven - Session 03
 
Matlab for diploma students(1)
Matlab for diploma students(1)Matlab for diploma students(1)
Matlab for diploma students(1)
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Chapter 3 - Flow of Control Part II.pdf
Chapter 3  - Flow of Control Part II.pdfChapter 3  - Flow of Control Part II.pdf
Chapter 3 - Flow of Control Part II.pdf
 
Cse lecture-7-c loop
Cse lecture-7-c loopCse lecture-7-c loop
Cse lecture-7-c loop
 
Introduction_to_Matlab_lecture.pptx
Introduction_to_Matlab_lecture.pptxIntroduction_to_Matlab_lecture.pptx
Introduction_to_Matlab_lecture.pptx
 
plsql tutorialhub....
plsql tutorialhub....plsql tutorialhub....
plsql tutorialhub....
 
Computer programming 2 Lesson 8
Computer programming 2  Lesson 8Computer programming 2  Lesson 8
Computer programming 2 Lesson 8
 
Parllelizaion
ParllelizaionParllelizaion
Parllelizaion
 
Introduction to programming in MATLAB
Introduction to programming in MATLABIntroduction to programming in MATLAB
Introduction to programming in MATLAB
 

More from Central university of Haryana

MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdfMATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdfCentral university of Haryana
 

More from Central university of Haryana (20)

Practical --2..pdf
Practical --2..pdfPractical --2..pdf
Practical --2..pdf
 
Practical --1.pdf
Practical --1.pdfPractical --1.pdf
Practical --1.pdf
 
ML Lab.docx
ML Lab.docxML Lab.docx
ML Lab.docx
 
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdfMATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
MATLAB-Cheat-Sheet-for-Data-Science_LondonSchoolofEconomics (1).pdf
 
LittleBookOfRuby.pdf
LittleBookOfRuby.pdfLittleBookOfRuby.pdf
LittleBookOfRuby.pdf
 
all matlab_prog.pdf
all              matlab_prog.pdfall              matlab_prog.pdf
all matlab_prog.pdf
 
Practical13.docx
Practical13.docxPractical13.docx
Practical13.docx
 
Practical 111.docx
Practical 111.docxPractical 111.docx
Practical 111.docx
 
Matlab Practical--11.pdf
Matlab Practical--11.pdfMatlab Practical--11.pdf
Matlab Practical--11.pdf
 
Matlab Practical--11.docx
Matlab Practical--11.docxMatlab Practical--11.docx
Matlab Practical--11.docx
 
Matlab Practical--9.docx
Matlab Practical--9.docxMatlab Practical--9.docx
Matlab Practical--9.docx
 
Matlab Practical-- 12.pdf
Matlab Practical-- 12.pdfMatlab Practical-- 12.pdf
Matlab Practical-- 12.pdf
 
Matlab practical ---9.pdf
Matlab practical ---9.pdfMatlab practical ---9.pdf
Matlab practical ---9.pdf
 
Matlab practical ---7.pdf
Matlab practical ---7.pdfMatlab practical ---7.pdf
Matlab practical ---7.pdf
 
Matlab practical ---6.pdf
Matlab practical ---6.pdfMatlab practical ---6.pdf
Matlab practical ---6.pdf
 
Matlab practical ---5.pdf
Matlab practical ---5.pdfMatlab practical ---5.pdf
Matlab practical ---5.pdf
 
Matlab practical ---4.pdf
Matlab practical ---4.pdfMatlab practical ---4.pdf
Matlab practical ---4.pdf
 
Matlab practical ---2.pdf
Matlab practical ---2.pdfMatlab practical ---2.pdf
Matlab practical ---2.pdf
 
Matlab practical ---1.pdf
Matlab practical ---1.pdfMatlab practical ---1.pdf
Matlab practical ---1.pdf
 
Matlab practical --8.pdf
Matlab practical --8.pdfMatlab practical --8.pdf
Matlab practical --8.pdf
 

Recently uploaded

Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisDr.Costas Sachpazis
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Ramkumar k
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxMustafa Ahmed
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfSkNahidulIslamShrabo
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsMathias Magdowski
 
Introduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxIntroduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxProfASKolap
 
Databricks Generative AI FoundationCertified.pdf
Databricks Generative AI FoundationCertified.pdfDatabricks Generative AI FoundationCertified.pdf
Databricks Generative AI FoundationCertified.pdfVinayVadlagattu
 
Presentation on Slab, Beam, Column, and Foundation/Footing
Presentation on Slab,  Beam, Column, and Foundation/FootingPresentation on Slab,  Beam, Column, and Foundation/Footing
Presentation on Slab, Beam, Column, and Foundation/FootingEr. Suman Jyoti
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...ronahami
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...IJECEIAES
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docxrahulmanepalli02
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...Amil baba
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsVIEW
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...IJECEIAES
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxKarpagam Institute of Teechnology
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxMustafa Ahmed
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashidFaiyazSheikh
 
Artificial Intelligence in due diligence
Artificial Intelligence in due diligenceArtificial Intelligence in due diligence
Artificial Intelligence in due diligencemahaffeycheryld
 

Recently uploaded (20)

Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
Introduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptxIntroduction-to- Metrology and Quality.pptx
Introduction-to- Metrology and Quality.pptx
 
Databricks Generative AI FoundationCertified.pdf
Databricks Generative AI FoundationCertified.pdfDatabricks Generative AI FoundationCertified.pdf
Databricks Generative AI FoundationCertified.pdf
 
Presentation on Slab, Beam, Column, and Foundation/Footing
Presentation on Slab,  Beam, Column, and Foundation/FootingPresentation on Slab,  Beam, Column, and Foundation/Footing
Presentation on Slab, Beam, Column, and Foundation/Footing
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded Systems
 
Artificial Intelligence in due diligence
Artificial Intelligence in due diligenceArtificial Intelligence in due diligence
Artificial Intelligence in due diligence
 

Matlab practical ---3.pdf

  • 1. Ashoka bairwa MATLAB ASHOK(191890) Practical—3 Theory: A loop is a set of instructions that is repeated until a given condition is met in computer science. Loops are used by programmers to repeat the task using values, add numbers, repeat functions, etc. The majority of modern programming languages support loops, though their implementations. But their syntax may differ. A. Types of Loop: three of the most common types of loop-------- • While loops • for loops • nested loops ▪ There may be a situation when you need to execute a block of code several times. In general, statements are executed sequentially. The first statement in a function is executed first, followed by the second, and so on. ▪ Programming languages provide various control structures that allow for more complicated execution paths. ▪ A loop statement allows us to execute a statement or group of statements multiple times. The drawing shows the general form of a loop statement for most programming languages. ▪ Matlab provides various types of loops to handle looping requirements including: while loops, for loops, and nested loops. If you are trying to declare or write your own loops, you need to make sure that the loops are written as scripts and not directly in the Command Window
  • 2. Ashoka bairwa MATLAB ASHOK(191890) 1)While Loop: The while loop repeatedly executes statements while a specified condition is true. • The syntax of a while loop in MATLAB is as following: While<expression> <statement> end
  • 3. Ashoka bairwa MATLAB ASHOK(191890) 2)For loop A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. The syntax of a for loop in MATLAB is as following: For index=values <programstatement> …… end
  • 5. Ashoka bairwa MATLAB ASHOK(191890) 3)The Nested Loops: Matlab also allows to use one loop inside another loop. The syntax for a nested for loop statement in MATLAB is as follows: For m=i:j Forn=i:j <statement>; end end or while <expression 1> while <expression 2> <statement> end end
  • 7. Ashoka bairwa MATLAB ASHOK(191890) Loop Control Statements : ❖ Loop control statements change execution from its normal sequence. ❖ When execution leaves a scope, all automatic objects that were created in that scope are destroyed. ❖ The scope defines where the variables can be valid in Matlab, typically a scope within a loop body is from the beginning of conditional code to the end of conditional code. ❖ It tells Matlab what to do when the conditional code fails in the loop. Matlab supports both break statement and continue statement. There are three case in loop control: ▪ Break ▪ Continue ▪ Switch
  • 8. Ashoka bairwa MATLAB ASHOK(191890) Break statement. ❖ The break statement terminates execution of for or while loops. Statements in the loop that appear after the break statement are not executed. ❖ In nested loops, break exits only from the loop in which it occurs. Control passes to the statement following the end of that loop.
  • 9. Ashoka bairwa MATLAB ASHOK(191890) Continue Statement: ❖ The continue statement is used for passing control to thenext iteration of a for or while loop. ❖ The continue statement in MATLAB works somewhat like the break statement. Instead of forcing termination, however, 'continue' forces the next iteration of the loop to take place, skipping any code in between.
  • 10. Ashoka bairwa MATLAB ASHOK(191890) Switch Statement: A switch statement help us choose one among a number of option using code that is easier. I Syntax of Switch Statement in Matlab switch switch_condition case case_condition statements_if_true case case_condition statements_if_true ... Otherwise_condition Statements_if_true end end……