This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


(Not recommended) Easy-to-use contour plotter

ezcontour is not recommended. Use fcontour instead.


h = ezcontour(...)


ezcontour(fun) plots the contour lines of fun(x,y) using the contour function. fun is plotted over the default domain: -2π < x < 2π, -2π < y < 2π.

fun can be a function handle for a MATLAB® file function or an anonymous function (see Create Function Handle and Anonymous Functions) or a character vector (see Tips).

ezcontour(fun,domain) plots fun(x,y) over the specified domain. domain can be either a 4-by-1 vector [xmin, xmax, ymin, ymax] or a 2-by-1 vector [min, max] (where min < x < max, min < y < max).

ezcontour(...,n) plots fun over the default domain using an n-by-n grid. The default value for n is 60.

ezcontour(axes_handle,...) plots into the axes with handle axes_handle instead of the current axes (gca).

h = ezcontour(...) returns the handle to a contour object in h.

ezcontour automatically adds a title and axis labels.


collapse all

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

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.


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


Passing the Function as a Character Vector

Array multiplication, division, and exponentiation are always implied in the character vector expression you pass to ezcontour. For example, the MATLAB syntax for a contour plot of the expression

sqrt(x.^2 + y.^2)

is written as

ezcontour('sqrt(x^2 + y^2)')

That is, x^2 is interpreted as x.^2 in the character vector you pass to ezcontour.

If the function to be plotted is a function of the variables u and v (rather than x and y), the domain endpoints umin, umax, vmin, and vmax are sorted alphabetically. Thus, ezcontour('u^2 - v^3',[0,1],[3,6]) plots the contour lines for u2 - v3 over 0 < u < 1, 3 < v < 6.

Passing a Function Handle

Function handle arguments must point to functions that use MATLAB syntax. For example, the following statements define an anonymous function and pass the function handle fh to ezcontour.

fh = @(x,y) sqrt(x.^2 + y.^2);

When using function handles, you must use the array power, array multiplication, and array division operators (.^, .*, ./) since ezcontour does not alter the syntax, as in the case with character vector inputs.

Passing Additional Arguments

If your function has additional parameters, for example, k in myfun:

function z = myfun(x,y,k)
z = x.^k - y.^k - 1;

then use an anonymous function to specify that parameter:


Introduced before R2006a

Was this topic helpful?