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.

NaNs by leaving them <strong>of</strong>f the plot. For example, if we allow plot to tryto join the points with a straight line, the values on either side <strong>of</strong> theNaNs terminate the line:plot(y)grid;boxIf we calculate the difference between y-values, the results involving NaNsare themselves NaN:>> diff(y)ans =Columns 1 through 121 1 1 NaN NaN 1 1 1 1 1 1 1Columns 13 through 191 NaN NaN 1 1 1 1If we calculate the cumulative sum <strong>of</strong> y, everything from the first NaNonwards is NaN:>> cumsum(y)ans =Columns 1 through 121 3 6 10 NaN NaN NaN ... NaNColumns 13 through 20NaN NaN NaN NaN NaN NaN NaN NaNmatlab’s surface plotting functions h<strong>and</strong>le NaNs in a similar way:z = peaks;z(5:35,18:22) = NaN;subplot(221)plot(z’)subplot(222)colormap(gray(64))imagesc(z)axis xysubplot(223)surfl(z)shading flatsubplot(224)contourf(z)c○ 2000 by CRC Press LLC

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

Saved successfully!

Ooh no, something went wrong!