0% found this document useful (0 votes)
42 views18 pages

4 - Chapter 5 Loop Statements and Vectorizing Codes

This document outlines a lecture on structured programming and loops in MATLAB for building and civil engineers. It discusses the different types of loops in MATLAB, including for loops, nested for loops, while loops, and how vectorization can be used instead of loops. The key topics covered are counted loops, conditional loops, using loops to sum numbers, pre-allocating vectors, plotting with loops, nested loop examples, counting and multiple conditions in while loops, and examples of vectorization for operations on vectors and matrices.

Uploaded by

David Hanna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
42 views18 pages

4 - Chapter 5 Loop Statements and Vectorizing Codes

This document outlines a lecture on structured programming and loops in MATLAB for building and civil engineers. It discusses the different types of loops in MATLAB, including for loops, nested for loops, while loops, and how vectorization can be used instead of loops. The key topics covered are counted loops, conditional loops, using loops to sum numbers, pre-allocating vectors, plotting with loops, nested loop examples, counting and multiple conditions in while loops, and examples of vectorization for operations on vectors and matrices.

Uploaded by

David Hanna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 18

Structured Programming and Applications for Building and

Civil Engineers

Lecture 4
by
Dr. Emre Erkmen, P.Eng.

Assistant Professor, Department of Building, Civil and Environmental Engineering,


Concordia University, Montreal

Office: EV 6.209
Phone:514 848 2424
Email: emre.erkmen@Concordia.ca
Lecture hours: Mondays 13:15-16:00
Office hours: Tuesdays 10:00-11:00

1
Structured Programming - Lecture 4

Outline of Today’s Lecture

Loops Statements

- The for Loop

- Nested for Loops

- While Loops

- Vectorizing
Structured Programming - Lecture 4

Loops in Matlab
There are two types of Loops in Matlab

- Counted Loops

- Conditional Loops

Alternatively Vectorization can be used in Matlab

- That goes over and assigns values to each component of a vector

3
Structured Programming - Lecture 4

Why do we need Loops?

4
Structured Programming - Lecture 4

For Loops
Structured Programming - Lecture 4

For Loops – Sum of numbers


Structured Programming - Lecture 4

Pre-allocating vectors

0
0
0
Structured Programming - Lecture 4

For Loops – Plotting


Structured Programming - Lecture 4

Nested For Loops


Structured Programming - Lecture 4

Nested For Loops - Example


Structured Programming - Lecture 4

Nested For Loops - Example


Structured Programming - Lecture 4

Nested For Loops - Example


Structured Programming - Lecture 4

While Loops
Structured Programming - Lecture 4

Counting in While Loops


Structured Programming - Lecture 4

Multiple Conditions in While Loops


Structured Programming - Lecture 4

Vectorization in Matlab

Multiply each component of v by 3

Using Loop Using Vectorization


Structured Programming - Lecture 4

Vectorization in Matlab

Calculate 5 factorial.

Using Loop Using Vectorization


Structured Programming - Lecture 4

Vectorization in Matlab
Determine the signs of each component of a matrix

Using Loop Using Vectorization

You might also like