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

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

View Full Document Right Arrow Icon
7. More Practice with Iteration and Conditionals Through Graphics For-Loop Problems Introduce While-Loops
Background image of page 1

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

View Full DocumentRight Arrow Icon
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.
Background image of page 2
Example
Background image of page 3

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

View Full DocumentRight Arrow Icon
Example
Background image of page 4
Example
Background image of page 5

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

View Full DocumentRight Arrow Icon
Hits = 50 Example
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
DrawRect -2 -1 0 1 2 3 4 5 6 -3 -2 -1 0 1 2 DrawRect(-1,-2,6,3,’y’)
Background image of page 9

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

View Full DocumentRight Arrow Icon
DrawDisk DrawDisk(1,3,4,’r’) -4 -2 0 2 4 6 -2 -1 0 1 2 3 4 5 6 7 8
Background image of page 10
DrawStar DrawStar(1,3,4,’g’) -4 -2 0 2 4 6 -2 -1 0 1 2 3 4 5 6 7 8
Background image of page 11

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

View Full DocumentRight Arrow Icon
A Simple 3-line Script Draw a black square. Then a magenta disk. Then a yellow star.
Background image of page 12
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
Background image of page 13

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

View Full DocumentRight Arrow Icon
A General Framework close all figure axis equal off hold on hold off shg Fragment involving DrawRect ’s, DrawDisk ’s and/or DrawStar ’s
Background image of page 14
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
Background image of page 15

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

View Full DocumentRight Arrow Icon
Some Matlab Graphics Commands % Exit the add-in mode… hold off % Bring the figure window to the % front… shg
Background image of page 16
Syntax Let’s look at the rules associated with using DrawRect, DrawDisk, and DrawStar.
Background image of page 17

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

View Full DocumentRight Arrow Icon
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
Background image of page 18
DrawRect DrawRect( , , , , ) Coordinates of lower left corner length width color
Background image of page 19

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

View Full DocumentRight Arrow Icon
Image of page 20
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online