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.

delete(h(1:2))We can now issue the correct text comm<strong>and</strong>:text(-.7,f(-.7),’f(x)’)Let us write an m-file to do this automatically. We’ll call it oops. Whenwe call oops without any argument, it should delete the last objectdrawn in the current axes. When called with an integer argument, n,oops should delete the last n objects drawn in the current axes. Thefollowing m-file is a possible solution. (The function nargin returns thenumber <strong>of</strong> arguments with which a function was called.)function oops(N)% OOPS Delete the last object plotted on the axes.% Repeating "oops" erases farther back in time.% OOPS does not work for title <strong>and</strong> labels; to% erase these, use "title(’’)" or "xlabel(’’)"if nargin = = 0 N = 1; endh = get(gca,’children’);delete(h(1:N));Let us see if oops works:clfplt(x,f(x))hold onplt(x,f(x/2))Nowwedoanoops to get rid <strong>of</strong> the shallow parabola,oopsNow plot the shallow one again with a different line style:c○ 2000 by CRC Press LLC

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

Saved successfully!

Ooh no, something went wrong!