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

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

View Full Document Right Arrow Icon
11. More on Arrays Square Bracket Notation Subscripts Plotting and color Built-In Functions: ginput, fill, sum, axis
Background image of page 1

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

View Full DocumentRight Arrow Icon
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.
Background image of page 2
Three “Short Vector” Examples Line Segments Little Polygons Color
Background image of page 3

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

View Full DocumentRight Arrow Icon
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])
Background image of page 4
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)
Background image of page 5

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

View Full DocumentRight Arrow Icon
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.
Background image of page 6
Built-In Function Fill fill( , , ) Vectors that specify the vertices of a polygon. Specify the fill-in color.
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
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)
Background image of page 9

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

View Full DocumentRight Arrow Icon
Any color is a mix of red, green, and blue. Represent a color with a length-3 vector and an “rgb convention”. c = [
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

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