Using ezcontour to Plot Anonymous Functions - dummies

Using ezcontour to Plot Anonymous Functions

By Jim Sizemore, John Paul Mueller

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.


  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.


  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.


  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).


  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.


  6. Type warning on and press Enter.

    MATLAB restores the use of warnings.


  7. Close your copy of MATLAB.