How to retrieve x, y values from surf given z?
Show older comments
I got surf by using
s = surf(X, Y, Z);
I know I can use xq, yq, and inter2 to retrieve zq from the surf, like following
zq = interp2(X, Y, Z, xq, yq);
but how to get all the x,y on the surf where z is a certain value.
Accepted Answer
More Answers (1)
Well, you can use
xq(zq==v)
xq(zq==v)
to find the points ( xq & yq ) where zq is equal to some specific value, v, but you're going to run into problems with comparing floats. A better approach would be to specify some tolerance, tol
xq(abs(zq-v)<tol)
yq(abs(zq-v)<tol)
4 Comments
Kyle Gao
on 24 Sep 2018
No, that is not what I mean. You interpolate first, then you find the coordinates.
xc=xq(abs(zq-v)<tol)
yc=yq(abs(zq-v)<tol)
It is the syntax for logical indexing. Basically you find the indices in zq where some condition is satisfied, in this case abs(zq-v)<tol, and then you put those indices directly into xq and yq.
I don't want to hijack Stephens answer, so I'll just leave another reply here.
" Actually, I want to get the [xy] within the area where zq-tol < zq < zq+tol "
This is exactly what
abs(zq-v)<tol
does... you obtain all values for zq +- tol. But honestly, the other answer is better, as it does not require any tolerance. The interpolation is kinda of integrated with the contour plot.
Categories
Find more on Contour Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!