Lab 4

Chapter 5 - Loop Statements and Vectorizing Code

Synopsis
In Lecture 5, we learned about a new type of control statement that allows us to repeatedly execute lines of code. We also learned the importance of leveraging MATLAB's ability to efficiently handle vectors and matrices in place of loops. In this lab, you will use the skills that you have learned so far to solve a challenege.


Daily Quiz

Quiz 8


Lab 4

This lab will be a bit different than previous exercises. First, form a group with two other students. In your group, examine the program output below. Your goal is to develop a MATLAB function that will produce the same output when passed the number five. Your code should be flexible enough to produce similar results for other values passed to your function. Take a top-down approach and a develop your algorithm. Once you have an algorithm, try to produce the code to accomplish each task. Then, once its working, see if you can make an improvement. At the end of lab, we will compare your solutions to see which group developed the most elegant function.

*****
****
***
**
*
**
***
****
*****

Answer Key

Timing Code
lab4key_20160217.m

Functions
lab4_loop.m
lab4_noloop.m


Final Words

There are many different ways to attack a problem. Today, you've had to use your skills and a bit of creativity to solve a difficult problem. In the next class, we will continue to build our skill set to help us tackle even larger MATLAB programs.