MATLAB Answers

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

41 views (last 30 days)
johan
johan on 16 Jul 2019
Answered: David K. on 16 Jul 2019
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

  0 Comments

Sign in to comment.

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.

  0 Comments

Sign in to comment.

Sign in to answer this question.