How do I create a surface or contour plot with x, y, and z vectors?

14 views (last 30 days)
I have three vectors that represent X-Y-Z triplets. How do I produce a contour or surface plot of this data using "meshgrid" and "griddata"? 

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 5 Dec 2023
Edited: MathWorks Support Team on 8 Dec 2023
In creating three-dimensional representations of data, it is often necessary to have data defined over evenly spaced, two-dimensional grids. These grids can be created using the "meshgrid" command. The "griddata" command can then be used to interpolate new z-values at the points contained in the output of "meshgrid".  The outputs of "griddata" and "meshgrid" can then be used as the inputs to plotting commands such as "surf", "mesh", or "contour" to visually represent the data, where the outputs of "meshgrid" are used as the x- and y-components and the output of "griddata" is uses as the z-component. 
Please refer to the following documentation for a detailed example.
MATLAB: Interpolating Scattered Data

More Answers (0)

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!