fcontour — Plot contour lines of a scalar function.
fcontour evaluates a function handle over a rectangular two-variable domain and renders contour lines from the sampled values.
Syntax
h = fcontour(f)
h = fcontour(f, xyinterval)
h = fcontour(___, Name, Value, ...)
h = fcontour(ax, ___)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
f | Any | Yes | — | Function of two variables, z = f(x,y). |
xyinterval | NumericArray | No | [-5 5 -5 5] | Two- or four-element domain vector. |
args | Any | Yes | — | Function-handle and optional domain arguments. |
name_value | Any | Variadic | — | MeshDensity and contour name/value arguments. |
ax | AxesHandle | Yes | — | Target axes handle. |
Returns
| Name | Type | Description |
|---|---|---|
h | NumericScalar | Handle to the rendered function contour. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:fcontour:InvalidArgument | Function handle, domain, mesh density, axes target, levels, or contour properties are invalid. | fcontour: invalid argument |
RunMat:fcontour:EvaluationFailed | A sampled function handle fails or does not return a scalar numeric value. | fcontour: function evaluation failed |
RunMat:fcontour:Internal | Contour construction or rendering fails unexpectedly. | fcontour: internal operation failed |
How fcontour works
fcontour(f)samplesf(x,y)on the default[-5 5 -5 5]domain.fcontour(f, [xmin xmax ymin ymax])uses an explicit rectangular domain; a two-element vector applies the same limits to both axes.fcontour(ax, ___)renders into the requested axes and returns a function-contour graphics handle.- Function-handle outputs must be scalar real numeric values at every sampled point; non-finite samples are preserved as contour discontinuities.
Options
'MeshDensity'controls the number of samples along each domain dimension. RunMat accepts integer values from 2 through 400.'LevelList','Levels','LevelStep','LevelListMode','LineColor','Color', and'LineWidth'use the same parsing path ascontour.'DisplayName'sets the function-contour graphics handle display name.
Does RunMat run fcontour on the GPU?
Callback sampling runs on the host.
The resulting contour uses the existing runmat-plot contour rendering path.
GPU memory and residency
fcontour is a callback-sampling builtin. It creates a new sampled contour plot and does not preserve input residency, because the input is a MATLAB function handle rather than a numeric provider buffer.
Examples
Plot function contours over the default domain
fcontour(@(x,y) sin(x) + cos(y));Set the domain, levels, and mesh density
h = fcontour(@(x,y) x.^2 - y.^2, [-2 2 -1 1], 'LevelList', [-1 0 1], 'MeshDensity', 75);Using fcontour with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how fcontour changes the result.
Run a small fcontour example, explain the result, then change one input and compare the output.
FAQ
Does fcontour evaluate the function handle on the GPU?⌄
No. MATLAB function handles can contain arbitrary user code, so RunMat samples them on the host and then hands the sampled grid to the contour renderer.
What happens if the function returns a vector?⌄
RunMat raises RunMat:fcontour:EvaluationFailed; each sampled point must produce one scalar numeric value.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · axes · barh · cla · clf · colorcube · colororder · copyobj · daspect · datacursormode · dataTipTextRow · figure · fill3 · findobj · fsurf · gobjects · groot · hgload · hgsave · hidden · histogram2 · hold · line · linkaxes · openfig · opengl · pan · parula · patch · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · stackedplot · subtitle · suptitle · textscatter · textscatter3 · triplot · waitbar · wordcloud · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zoom
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how fcontour is executed, line by line, in Rust.
- View the source for fcontour in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.