Obtain z-values in contour plot using x,y coordinates of a point of interest

12 views (last 30 days)
Dear Matlab community,
For a project I would like to know the Z-values along a line in the contour plot. The line consists of multiple points, x,y coordinates, at which I would like to read the Z-value from the contour plot. In practice it maybe means that some points require an interpolation, because not all x,y-values are present as input.
Is there a function available which can be used to obtain the z-value for a certain x,y-coordinate in a contour plot? If not, do you maybe have an idea how I could obtain these values?
Regards, Johan

Answers (1)

David K.
David K. on 16 Jul 2019
You could potentially use the interp2 function. If you used
Contour(X,Y,Z);
you could then use
interp2(X,Y,Z,Xq,Yq);
to obtain the Z values at the new Xq and Yq.
Depending on your original data set this may not work if your X or Y are not monotonically increasing.
You may also have some issue with column and row vectors in interp2, if they are not matrices, X's need to be row vectors and Y's need to be column vectors.
Hope this helps.

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!