MATLAB For Dummies
Book image
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 authors:

John Paul Mueller is an author and technical editor with experience in application development, database management, machine learning, and deep learning. He has written hundreds of books and articles helping everyday people learn everything from networking to database management.

John Mueller has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services (AWS). Luca Massaron, a Google Developer Expert (GDE),??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques.

This article can be found in the category: