# Lec7 - 7 More Practice with Iteration and Conditionals...

This preview shows pages 1–20. Sign up to view the full content.

7. More Practice with Iteration and Conditionals Through Graphics For-Loop Problems Introduce While-Loops

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
We will Draw Pictures Using Three User-Defined * Graphics Functions DrawRect Rectangles DrawDisk Circles DrawStar 5-pointed Stars *As opposed to built-in functions like sqrt and rem.
Example

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Example
Example

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Hits = 50 Example
Why? • Get more practice with loops and if . • Warm-up to using Matlab’s graphics functions which use arrays • Warm-up to writing your own user- defined functions

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
What is the last line of output? x = 1 y = x; x = 2*x end Question Time A. 1 B. 2 C. 4 D. 8
DrawRect -2 -1 0 1 2 3 4 5 6 -3 -2 -1 0 1 2 DrawRect(-1,-2,6,3,’y’)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
DrawDisk DrawDisk(1,3,4,’r’) -4 -2 0 2 4 6 -2 -1 0 1 2 3 4 5 6 7 8
DrawStar DrawStar(1,3,4,’g’) -4 -2 0 2 4 6 -2 -1 0 1 2 3 4 5 6 7 8

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
A Simple 3-line Script Draw a black square. Then a magenta disk. Then a yellow star.
Solution close all figure axis equal off hold on DrawRect(-1,-1,2,2,'k') DrawDisk(0,0,1,'m') DrawStar(0,0,1,'y') hold off

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
A General Framework close all figure axis equal off hold on hold off shg Fragment involving DrawRect ’s, DrawDisk ’s and/or DrawStar ’s
Some Matlab Graphics Commands % Close all figure windows… close all % Open a new figure window figure % Set x and y scaling to be the % same and do not display axes axis equal off % “Add-in mode” is on… hold on

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Some Matlab Graphics Commands % Exit the add-in mode… hold off % Bring the figure window to the % front… shg
Syntax Let’s look at the rules associated with using DrawRect, DrawDisk, and DrawStar.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
DrawRect(-1,-2,6,3,’y’) DrawRect Input 3 (-1,-2) 6 A yellow 6x3 rectangle at (-1,-2) -1 -2 6 3 ‘y’ Output
DrawRect DrawRect( , , , , ) Coordinates of lower left corner length width color

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 54

Lec7 - 7 More Practice with Iteration and Conditionals...

This preview shows document pages 1 - 20. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online