reshape data to fit into surf/contour

31 vues (au cours des 30 derniers jours)
feynman feynman
feynman feynman le 25 Nov 2024 à 11:05
Commenté : Walter Roberson il y a environ 6 heures
nodalPositions is a 2*100 double matrix storing the nodal positions of a PDE on a 2D domain with 100 nodes. x=nodalPositions(1,:) and y=nodalPositions(2,:) are the nodal x and y coordinates. The solution of the PDE, u, is a 1*100 double array. One can plot(x,y,'.') to plot the nodes in a plane or plot3(x,y,u,'.') to plot u in 3-space. How to reshape x, y, u so that one can surf(x,y,u) or contour(x,y,u)?

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Nov 2024 à 11:12
You cannot do that.
Or,
N = 100;
[minx, maxx] = bounds(x);
[miny, maxy] = bounds(y);
[Xg, Yg] = ndgrid( linspace(minx, maxx, N), linspace(miny, maxy, N));
F = scatteredInterpolant(x(:), y(:), u(:));
Ug = F(Xg, Yg);
surf(Xg, Yg, Ug, 'edgecolor', 'none');
  5 commentaires
Stephen23
Stephen23 il y a environ 19 heures
Modifié(e) : Stephen23 il y a environ 19 heures
"May I ask why?"
You defined colinear data: what do you expect the interpolation to return? Take a look at the size of Ug.
Walter Roberson
Walter Roberson il y a environ 6 heures
@Stephen23 is right. When y = x then all of the data falls along a single line. Triangulation of a single line fails.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by