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.

clfaxes(’pos’,[.2 .1 .7 .4])x = linspace(0,2);plt(x,humps(x))axis tightzeroaxesaxes(’pos’,[.2 .5 .7 .4])plt(x,cumsum(humps(x)))set(gca,’xticklabel’,’’)axis tight32.3 SubplotsMultivariate data can be displayed by plotting arrays <strong>of</strong> subplots. Forexample, a column <strong>of</strong> x–y plots can represent y plotted as a function <strong>of</strong>x <strong>and</strong> z. A sequence <strong>of</strong> such columns can represent another variable,so that you can see y plotted as a function <strong>of</strong> x, z, <strong>and</strong> t. matlab’ssubplot comm<strong>and</strong> is an easy way <strong>of</strong> generating arrays <strong>of</strong> plots, but youhave no control over the precise positioning; the gap between the plots,for example, is not controllable. The m-file pickbox (see companions<strong>of</strong>tware) is designed for such cases. You give pickbox the number <strong>of</strong>rows <strong>and</strong> columns you want in your array <strong>of</strong> plots, <strong>and</strong> pick out thenumber <strong>of</strong> the plot you want (in the same way as for subplot). You canalso specify the amount <strong>of</strong> x <strong>and</strong> y space between the plots as well as theamount <strong>of</strong> white space around the entire plot array. This space can beused for row <strong>and</strong> column labels. In the following example we generatesamples <strong>of</strong> the functionB(x, y, t) =(1− e −(2x)2 −y 2 )/tover a three-dimensional grid <strong>of</strong> x, y, <strong>and</strong> t. We display the samples bydrawing repeated plots <strong>of</strong> B as a function <strong>of</strong> x <strong>and</strong> arraying them overa matrix <strong>of</strong> rows <strong>and</strong> columns indexed by y, <strong>and</strong> t, respectively: 15xv = -1:.1:1;yv = -1:.2:1;tv = 1:5;[x,y,t] = ndgrid(xv, yv, tv);B = (1 - exp(-(2*x).^2 - y.^2))./t;Nx = length(xv);Ny = length(yv);Nt = length(tv);clfcount = 0;top = max(max(max(B)));15 The code is given in the companion m-file plotbxyt.c○ 2000 by CRC Press LLC

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

Saved successfully!

Ooh no, something went wrong!