Home

Using ezcontour to Plot Anonymous Functions

|
Updated:  
2016-03-26 08:24:53
|
From The Book:  
MATLAB For Dummies
Explore Book
Buy On Amazon

MATLAB provides a wealth of easy plotting methods. When you couple these plotting methods with anonymous functions, you can work quickly on solving problems rather than waste time trying to figure out the more complex commands in MATLAB. Anonymous functions make creating a function easy without all the usual overhead of a named function in a file.

The following steps demonstrate how to combine anonymous functions with an ezcountour() plot:

  1. Open your copy of MATLAB.

    You see the MATLAB application start with the Command window displayed.

    image0.jpg
  2. Type format compact and press Enter.

    MATLAB displays the output of anything you type using the compact format, which means without any added whitespace. Notice the use of color coding. The command is in black type, the argument is in purple. Color coding makes it possible for you to understand the MATLAB input with greater ease.

    image1.jpg
  3. Type warning off and press Enter.

    It's possible that some operations will generate a warning that has nothing to do with the actual functionality of the task being performed. One such warning is MATLAB's advice about optimizing functions. Using an anonymous function in the manner shown in this procedure could generate an optimization warning that won't prove very helpful.

    image2.jpg
  4. Type fxy = @(x,y)[sin(x)*cos(y)]; and press Enter.

    This step creates an anonymous function that is placed within fxy. The function has no name. It does accept two input values, x and y. The resulting output is expressed by the formula: sin(x)*cos(y).

    image3.jpg
  5. Type ezcontour(fxy, [-2, 2]) and press Enter.

    The call to ezcontour() creates a contour plot for you. The first argument, fxy, contains the function used to create the plot. The second argument contains the input values for the plot, which range from -2 to 2.

    image4.jpg
  6. Type warning on and press Enter.

    MATLAB restores the use of warnings.

    image5.jpg
  7. Close your copy of MATLAB.

About This Article

This article is from the book: 

About the book author:

Jim Sizemore is Professor of Physics and Engineering at Tyler Junior College. For over 25 years he s worked in the semiconductor and software industries as a process engineer, device physicist, and software developer and has been teaching college physics, engineering, and math for the last 13 years.

John Paul Mueller is a freelance author and technical editor. He has writing in his blood, having produced 100 books and more than 600 articles to date. The topics range from networking to home security and from database management to heads-down programming. John has provided technical services to both Data Based Advisor and Coast Compute magazines.