I am trying to interpret 3D plots but its driving me nuts.
Lets say I want to see the relationship between 3 variables and I have data as following:
x = 1:1:10 #values between 1 and 10 inclusive
y = 101:1:110 #values between 101 and 110 inclusive
[X,Y] = meshgrid(x,y) # I don't know this part - why it makes a matrix with same values in different rows
Z = X.+Y #I want to make it as simple as the sum of x and y
surf(X,Y,Z)
When I run this in matlab, I get a plot like this image:
On a 2D graph, if we know the x value, we can easily find the y value and vice versa. How can I do the same with this image.
Thanks
Best Answer
If you only know the $x$ value this is not enough to find the $y$ value or $z$ value.
If you know the $x$ value AND the $y$ value, you could find the $z$ value.
For example $x=2$, $y=1$, you may consider $x=2$ to be a plane $p$ parallel to the $yz$-coordinate plane, and consider $y=1$ to be a plane $q$ parallel to the $xz$-coordinate plane, the intersection of planes $p$ and $q$ is a vertical line $v$ which intersects the graph at a certain point, namely $(2,1,3)$ which you could interpret as "finding the $z$ value", $z=3$, from $x=2$ and $y=1$. Alternatively, and easier, $x=2$ is a line parallel to the $y$ axis in the $xy$-coordinate plane, $y=1$ is a line perpendicular to $x=2$ and parallel to the $x$ axis in the $xy$-coordinate plane, they intersect at a point $P=(2,1,0)$ in the $xy$-coordinate plane, and the vertical line $v$ through $P$ intersects the graph at $(2,1,3)$.
Given $z$ you cannot easily find $x$, unless you know $y$, at least for the example that you consider. In general you need not be able to find $x$ even if you know both $y$ and $z$, and you don't need 3D to illustrate this difficulty. Your statement:
"On a 2D graph, if we know the x value, we can easily find the y value and vice versa" is not quite right (in the "vice versa" part), for example if $y=x^2$ and $y=4$ then there are two possible values for $x$, $2$ and $-2$.
If $y=\sin(x)$ and $y=\dfrac12$ then there are countably infinitely many values for $x$, $\dfrac\pi6$, $\dfrac{5\pi}6$, $\dfrac{13\pi}6$, $\dfrac{-7\pi}6$, to list a few. If $y=\dfrac{x^2}{x^2}$ and $y=1$ then there are continuum (infinitely, with the cardinality of the real line) many values for $x$, namely all $x$ in $(-\infty,0)\cup(0,\infty)$, so it is in general not true, even on a 2D graph, that if you know the $y$ value then you could easily find the $x$ value.
It is hard to say what exactly your difficulty is, perhaps you are spoiled by matlab. Did you ever try to plot at least one 3D graph by hand? If the answer is no, then no wonder you could not understand what matlab shows you. (If the answer is yes, then I am puzzled, you shouldn't have had any difficulties with the above question.)
Edit. I read your comment. Perhaps it is not matlab to blame: When you draw in a 2D plane (e.g. a computer screen or a piece of paper) an object that naturally lives in 3D, you lose information, the result being that there is an inherent difficulty to figure $z$ if you know $x,y$. (You could make matlab do it, if matlab knows the function that defined $z$ in terms of $x,y$ but if you are only given the graph, then there is ambiguity).
I will illustrate the difficulty with a certain example (even if it might not quite exactly relate to your question, but I already made the pictures this way), and then indicate (leaving the details to you) another example which might be more closely related to what you ask.
Say you are given a 3D coordinate system, and more precisely what you see is a 2D projection on the screen. You just see the three coordinate axes (and matlab gives you something that looks like a cube, but this in essence is the coordinate axes along with some parallel lines that are redundant and meant to perhaps make it easier to navigate the picture). Say you are also given a point $P$, as shown in this picture:
You may try to figure the $x,y,z$ coordinates of $P$ but this can consistently be done in more than one way, so if you want to make this task unambiguous, you need more information. Say you are now given $z$. Then you could connect the point $z$ (more precisely $(0,0,z)$) with $P$, add a couple of lines, one parallel to line $zP$, the other parallel to the $z$-axis, and then their intersection $Q$ is the projection of $P$ onto the $xy$-coordinate plane, as shown on the next picture:
Now you could add a couple of lines through $Q$, parallel to the $x$-axis and the $y$-axis respectively, to get the $x$ and the $y$ coordinates of $P$ on the picture, as follows:
But, starting with what looks like "the same" $P$ (in the very first picture), and a different $z$, and following the same procedure, we get different $x,y$ as shown below:
Now (to turn things around and make this illustration more closely match your comment below) given $x,y$ you could easily construct $Q=(x,y,0)$ and draw a vertical line from $Q$ (as well as a line through $Q$ and the origin). Given also the graph of a surface, then you could find the intersection $P$ of that vertical line with the surface, and from there determine $z$ (drawing certain parallel lines, and taking certain intersections as illustrated in the picture below), but you cannot determine $P$ unambiguously just from the 2D picture, and a different $P$ will give you a different $z$.
The above explanation only shows that you cannot determine $z$, given $x,y$, from the 2D graph of the surface alone. Or course, on the other hand, if you are given explicitly $z=f(x,y)$ it will be easy to make matlab to plot the exact point $(x,y,z)$ and to determine the value of $z$, so also to plot the point $(0,0,z)$ on the $z$-axis.