Main Content

ezcontour

(Not recommended) Easy-to-use contour plotter

    ezcontour is not recommended. Use fcontour instead. For more information, see Compatibility Considerations.

    Description

    example

    ezcontour(f) plots the contour lines of the function z = f(x,y) using the contour function. The function plots f over the default interval [-2π 2π] for x and y.

    ezcontour automatically adds a title and axis labels to the plot.

    example

    ezcontour(f,xyinterval) plots over the specified interval. To use the same interval for both x and y, specify xyinterval as a two-element vector of the form [min max]. To use different intervals, specify a four-element vector of the form [xmin xmax ymin ymax].

    example

    ezcontour(___,n) plots using an n-by-n grid. Use this option after any of the input argument combinations in the previous syntaxes.

    ezcontour(ax,___) plots into the axes specified by ax instead of the current axes. Specify the axes before any of the input argument combinations in any of the previous syntaxes.

    c = ezcontour(___) returns the contour object. Use c to modify the contour after it is created. For a list of properties, see Contour Properties.

    Examples

    collapse all

    This mathematical expression defines a function of two variables, x and y.

    f(x,y)=3(1-x)2e-x2-(y+1)2-10(x5-x3-y5)e-x2-y2-13e-(x+1)2-y2

    The ezcontour function requires a function handle argument. Write this mathematical expression in MATLAB® syntax as an anonymous function with handle f. You can define an anonymous function in the command window without creating a separate file. For convenience, write the function on three lines.

    f = @(x,y) 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...
       - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
       - 1/3*exp(-(x+1).^2 - y.^2);

    Pass the function handle, f, to ezcontour. Specify a domain from -3 to 3 in both the x-direction and y-direction and use a 49-by-49 computational grid.

    ezcontour(f,[-3,3],49)

    Figure contains an axes object. The axes object with title 3 blank ( 1 - x ) Squared baseline blank e x p ( - ( x Squared baseline ) - ( y + 1 ) Squared baseline ) - . . . - 1 / 3 blank e x p ( - ( x + 1 ) Squared baseline - y Squared baseline ) contains an object of type contour.

    In this particular case, the title is too long to fit at the top of the graph, so MATLAB abbreviates it.

    Input Arguments

    collapse all

    Function to plot, specified as a character vector, string scalar, or function handle to a named or anonymous function.

    Specify a function of the form z = f(x,y). The function must accept two matrix input arguments and return a matrix output argument of the same size.

    When specifying the function as a character vector or string scalar, array multiplication, division, and exponentiation are always implied. For example, x^2 is interpreted as x.^2.

    Example: 'sqrt(x^2 + y^2)'

    When specifying the function as a function handle, use array operators instead of matrix operators for the best performance. For example, use .* (times) instead of * (mtimes).

    Example: @(x,y) sin(x).*cos(y)

    Plotting interval for x and y, specified in one of these forms:

    • Vector of form [min max] — Use the interval [min max] for both x and y.

    • Vector of form [xmin xmax ymin ymax] — Use the interval [xmin xmax] for x and [ymin ymax] for y.

    Size of the grid, specified as a positive integer. The grid has dimensions n-by-n.

    Axes object. If you do not specify an axes object, then the ezcontour uses the current axes.

    Compatibility Considerations

    expand all

    Not recommended starting in R2016a

    Extended Capabilities

    Introduced before R2006a