Find Z-value corresponding to X and Y points

조회 수: 13 (최근 30일)
Kyle Chudler
Kyle Chudler 2015년 7월 1일
댓글: Akbar Raza 2017년 3월 16일
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!

답변 (1개)

Mike Garrity
Mike Garrity 2015년 7월 1일
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.
  • 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.
  댓글 수: 7
Akbar Raza
Akbar Raza 2017년 3월 16일
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
Akbar Raza 2017년 3월 16일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by