why surf function does not show complete data
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ham Man
el 8 de Jul. de 2022
Comentada: Ham Man
el 8 de Jul. de 2022
I have a plot from pcolor function which is a grid of 8X5. but when plot these data with surf function one grid of row and one of column are eliminated. Thanks for any advice! Plots are atteched.
1 comentario
John D'Errico
el 8 de Jul. de 2022
See my answer. The complete grid was surfed. You just need to focus on the correct thing.
Respuesta aceptada
John D'Errico
el 8 de Jul. de 2022
Editada: John D'Errico
el 8 de Jul. de 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
surf(x,y,z)
xlabel x
ylabel 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.
mesh(x,y,z,'facecolor','none')
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.)
pcolor(x,y,z)
colorbar
I even added a colorbar there. Lets do it using surf too.
surf(x,y,z)
view(0,90)
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:
set(cax,'View',[0 90]);
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.
4 comentarios
John D'Errico
el 8 de Jul. de 2022
What you showed in your question is an issue only because we don't know how you plotted them. When you show only a picture, we don't know what code generated it. And that means you were plotting two different things.
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!