why surf function does not show complete data
5 views (last 30 days)
John D'Errico on 8 Jul 2022
Edited: John D'Errico on 8 Jul 2022
Um, EXACTLY what is not shown? :)
LOOK CAREFULLY at the surface you show. You surfed a 8x5 grid, right? Now, count the lines shown on that surface. Do you see 8 lines along one edge, and 5 lines along the other?
Instead, you seem to be counting the patches. Yes, there is a 7x4 grid of patches. But it is the lines that matter. surf does not plot patches at a constant level. Instead, it plots a quasi-rectangular patch connecting 4 points. Then it shows that patch in some color. But it is the EDGES that matter, NOT the patch colors. The patch color is just there to make it look pretty and help you to see the surface.
For example. consider this case, with my own 8x5 grid.
[x,y] = meshgrid(1:5,1:8);
z = x + y
Look carefully now, and count. z was a 8x5 array. So there are 5 lines perpendicular to the x axis, and 8 lines running perpendicular to the y axis.
Again, we see only 7x4 patches. But that is not what you need to be looking at. It is the black lines that correspond to the grid you plotted. Perhaps better is to completely turn off the facets, to then see what is being plotted. Do you see here, that the grid plotted really is a 8x5 grid? The facets you saw in the surf plot were just an illusion.
Perhaps another way to look at it is to use a shaded surface, with interpolated shading.
H = surf(x,y,z);
H.FaceColor = 'interp';
Again, we see that the real surface is truly derived from an 8x5 grid. COUNT THE EDGES! The patches here now have interpolated colors, which does not suggest a 7x4 array, as does the basic result that comes from surf.
My guess is it is not that hard to be confused. But that is what happened. You mistook the patches as showing what was significant, but in reality, it is the edges that really matter. (Note that pcolor and surf are in reality the same thing, except that pcolor is just a surf viewed from directly above.)
I even added a colorbar there. Lets do it using surf too.
So pcolor is just a call to surf, then shifting the view angle to directly above.
If you look carefully at the code for pcolor, you will see this line of code near the end:
Surely you CANNOT say there is any difference in what pcolor shows, compared to surf? It is the same 8x5 grid. The colored patches are identically the same number whether pcolor or surf plotted them, always a 7x4 grid of PATCHES. But it is the lines that are what correspond to what is plotted. Don't focus on the patches.