CS 100 M Lecture 11

# CS 100 M Lecture 11 - 11 More on Arrays Square Bracket...

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

11. More on Arrays Square Bracket Notation Subscripts Plotting and color Built-In Functions: ginput, fill, sum, axis

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

View Full Document
The Square Bracket These are equivalent: x = linspace(0,1,5) x = [ 0 .25 .50 .75 1.00] 0.00 0.25 0.50 0.75 1.00 x: Handy for setting up “short” vectors.
Three “Short Vector” Examples Line Segments Little Polygons Color

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

View Full Document
Plotting a Line Segment a = 1; b = 2; c = 3; d = 4; plot([a c],[b d]) This draws a line segment that connects (1,2) and (3,4): A natural mistake: plot([a b],[c d])
Drawing Little Polygons x = [a a+L a+L a a]; y = [b b b+W b+W b]; plot(x,y) This draws an L-by-W rectangle with lower left corner at (a,b): Connect (a,b) to (a+L,b) to (a+L,b+W) to (a,b+W) to (a,b)

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

View Full Document
Coloring Little Polygons x = [a a+L a+L a a]; y = [b b b+W b+W b]; fill(x,y,c) This draws an L-by-W rectangle with lower left corner at (a,b) and colors with the color named by c: Connect (a,b) to (a+L,b) to (a+L,b+W) to (a,b+W) to (a,b) and then fill it in.
Built-In Function Fill fill( , , ) Vectors that specify the vertices of a polygon. Specify the fill-in color.

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

View Full Document
x = [0.11 -0.99 -0.78 0.95] y = [0.99 0.08 -0.62 -0.30] fill(x,y,’y’) -1 -0.5 0 0.5 1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
DrawRect function DrawRect(a,b,L,W,c) x = [a a+L a+L a a]; y = [b b b+W b+W b]; fill(x,y,c)

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

View Full Document
Any color is a mix of red, green, and blue. Represent a color with a length-3 vector and an “rgb convention”. c = [
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 42

CS 100 M Lecture 11 - 11 More on Arrays Square Bracket...

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

View Full Document
Ask a homework question - tutors are online