- That == is an exact comparison. You might need to do a comparison with a tolerance.
- Because your XData & YData are not monotone, you might get more than one match. In that case, r & c will be vectors.
Find Z-value corresponding to X and Y points
38 views (last 30 days)
Show older comments
I'm plotting something using pcolor in Matlab. I am using the code pcolor(X,Y,Z), where X and Y are 2-D matrices of equal size to Z.
My question is that, given a value of X and Y, how can I find the value of Z at this point. For example, the value of Z when X = 10.32 and Y = -12.5. I know how to find the location in the the X and Y matrices where these values occur, but I'm not sure how get the Z value from this.
The Z matrix isn't simply an analytical function of X and Y, rather I was just given value of Z and their corresponding X and Y points.
X and Y are NOT monotonically increasing.
The values of X and Y that I want to find Z at will always be present in the original X and Y matrices. For example, I want to find the value of Z corresponding to the X value at X(10,20) and Y value at Y(15,25).
Thanks!
0 Comments
Answers (1)
Mike Garrity
on 1 Jul 2015
If the X & Y are in the input matrices, then you can do the following:
[x,y,z] = peaks;
h = surf(x,y,z);
[r,c] = find((h.XData==2.625) & (h.YData==2.625));
disp(h.ZData(r,c))
A couple of things to watch out for.
7 Comments
Akbar Raza
on 16 Mar 2017
Thanks Walter. Now what I need to do is to stack multiple copies of this data in the z-dimension which will result effectively in a 4D plot. Currently, if we assume that the same data is being used multiple times in the z-dimension, then how can I have a volumetric structure such that it becomes a continuous form of scatter3 plot. Need your help with this problem
Akbar Raza
on 16 Mar 2017
what I want eventually is stacking all the slices to make the attached volumetric structure. How can I do that? Please ignore the axis in this figure
See Also
Categories
Find more on Surface and Mesh 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!