for Loops
Q. What is a for loop?
A. A for loop is an iteration structure that repeats a set of instructions a given number of times.
Example application: Coach to team – “Run around this field 10 times.”
Users are encouraged to read through the following primers:
For Loops Primer
For Loops Applications
For Loops Advanced Primer
Examples | Tutorials | MATLAB programs |
---|---|---|
Write a statement N times | forloop_writeNtimes.m | |
Display numbers from a Start Count to an End Count (specified by the user) | forloopdisplaycount.m | |
Build a vector | forloop_buildvector1.m | |
Compute cos(x) using the Taylor series | forloop_cosxtaylorseries.m | |
Compute the sum of all integers from 1 to N. | runningsum1toN.m | |
Convert percent grades to letter grades. | classpercent_to_letter_grade.m | |
Build a vector in MATLAB using given discontinuous function f(t) (where f(t) is different for different intervals). | TBD | |
Build a matrix using a nested for loop | forloops_buildmatrix1.m | |
A function within a for loop used to compute and plot the trajectory of a projectile. | projectiletrajectory.m trajectory_theta.m |
File needed for the exercises: roddata.mat - Right-click and save-as if necessary