Documentation

ezcontourf

(Not recommended) Easy-to-use filled contour plotter

ezcontourfis not recommended. Usefcontourinstead.

Syntax

ezcontourf(fun)
ezcontourf(fun,domain)
ezcontourf(...,n)
ezcontourf(axes_handle,...)
h = ezcontourf(...)

Description

ezcontourf(fun)plots the contour lines offun(x,y)using thecontourffunction.funis plotted over the default domain: -2π <x< 2π, -2π <y< 2π.

funcan be a function handle, a character vector, or a string (seeTips).

ezcontourf(fun,domain)plotsfun(x,y)over the specifieddomaindomaincan be either a 4-by-1 vector[xmin,xmax,ymin,ymax]or a 2-by-1 vector[min,max], wheremin<x<max,min<y<max).

ezcontourf(...,n)plotsfunover the default domain using ann-by-ngrid. The default value fornis 60.

ezcontourf(axes_handle,...)plots into the axes with the handleaxes_handleinstead of into the current axes (gca).

h = ezcontourf(...)returns the handle to a contour object inh

ezcontourfautomatically adds a title and axis labels.

Examples

collapse all

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

Theezcontourffunction requires a function handle argument. Write this mathematical expression in MATLAB® syntax as an anonymous function with handlef。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);

传递函数handle,f, toezcontourf。Specify a domain from -3 to 3 in both the x-direction and y-direction and use a 49-by-49 computational grid.

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

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

Tips

Passing the Function as a Character Vector or String

Array multiplication, division, and exponentiation are always implied in the expression you pass toezcontourf。例如,MATLAB®syntax for a filled contour plot of the expression

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

is written as

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

That is,x^2is interpreted asx.^2in the character vector or string you pass toezcontourf

If the function to be plotted is a function of the variablesuandv(rather thanxandy), then the domain endpointsumin,umax,vmin, andvmaxare sorted alphabetically. Thus,ezcontourf('u^2 - v^3',[0,1],[3,6])plots the contour lines foru2-v3over 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 handlefhtoezcontourf

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

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

Passing Additional Arguments

If your function has additional parameters, for example,kinmyfun:

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

那你这n use an anonymous function to specify that parameter:

ezcontourf(@(x,y)myfun(x,y,2))

Introduced before R2006a

Was this topic helpful?