Surf plot and the slices do not match

5 visualizaciones (últimos 30 días)
Maria Oprea
Maria Oprea el 5 de Sept. de 2023
Comentada: Maria Oprea el 5 de Sept. de 2023
I am trying to do a surface plot of a 3D function at slice (which corresponds to time = 1). To do so I create a grid with and . Here's the code:
[W, Theta] = meshgrid(grid(1, :), grid(2, :));
surf(W, Theta,reshape( u(2, :, :), N, N), 'EdgeColor','none');
xlabel("$x$", 'Interpreter','latex');
ylabel("$p$", 'Interpreter','latex');
I obtain:
Notice this discontinuity at x = 1.5 for example along the p-axis. This is a close up view from above, and one from the side.
However, if I plot just a slice using the normal plot function in matlab there is no discontinuity. Here's the code and the plot:
plot(grid(2, :), reshape(u(2, 40, :), 50, 1)); xlabel('p'); ylabel('u(x = 1.59, p)')
here index 40 corresponds to x = 1.59.
Does anybody know what is going on in here? Any help/hint would be greatly appreciated!!

Respuestas (1)

Bruno Luong
Bruno Luong el 5 de Sept. de 2023
Editada: Bruno Luong el 5 de Sept. de 2023
You mix grids, with meshgrid and surf:
  • grid(;,1) => 3rd dimension of u, W, you label it x
  • grid(;,2) => 2nd dimension of u, THETA, you label it p, and describe it as y !!!
But then you plot using plot you considered then
  • the 3rd dimension of u for p
which is incoherent with the surface plot. The plot wit plot is for p constant with x varies, assuming the surface is correct.
Also your variable naming is not coherent and all over the places : W, x, THETA, p, y, grid(:,1), grid(:,2) etc... There is some basic discipline in naming in science that you need to learn and apply if you don't want to waste your time for such problem.

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!

Translated by