12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

z = 5*ones(3,3)z =5 5 55 5 55 5 5>> surf(x,y,z)0 −1But, <strong>of</strong> course, the z values need not be constant:>> z = [[4; 5; 6] [4.5; 5; 5.5] [4.9; 5; 5.1]]z =4.0 4.5 4.95.0 5.0 5.066.0 5.5 5.15.5>> surf(x,y,z)565.554.53 44.521013 4210−101Other graphics functions can also h<strong>and</strong>le nonrectangular grids. Here isan example using the contour function:35.8cs = contour(x,y,z,’k’);clabel(cs)i = [1 4 7 9 6 3 1];hold onplt(x(i),y(i),’:’)2.521.510.55.654.85.44.2 4.4 4.65.20−1 −0.5 0 0.5 1The contour levels are labelled using the clabel comm<strong>and</strong>, <strong>and</strong> theregion defined by the x <strong>and</strong> y points is outlined by the dotted line. Thecontours that the labels refer to are marked by small plus signs ‘+’. Theoutline around the bent domain is drawn using the x <strong>and</strong> y matricesindexed using the vector i. The vector i extracts the appropriate pointsfrom the x <strong>and</strong> y matrices using the columnar indexing described in section3.4 on page 9. The other surface graphics functions—mesh, surfl,surfc, <strong>and</strong> contourf—can h<strong>and</strong>le such nonrectangular grids equallywell. The image <strong>and</strong> imagesc functions assume equally spaced rectangulargrids <strong>and</strong> cannot h<strong>and</strong>le anything else. (The pcolor functiondraws a surface <strong>and</strong> sets the view point to directly overhead, so it is notdiscussed separately.)Let us now do another example <strong>of</strong> a surface defined over a nonrectangulargrid. We want to define a set <strong>of</strong> points that cover the semi-c○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!