reshape data to fit into surf/contour

조회 수: 19 (최근 30일)
feynman feynman
feynman feynman 2024년 11월 25일 11:05
댓글: Walter Roberson 대략 24시간 전
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)?

답변 (1개)

Walter Roberson
Walter Roberson 2024년 11월 25일 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');
  댓글 수: 2
feynman feynman
feynman feynman 2024년 11월 28일 10:23
many thanks for your code.
Error using surf
Data dimensions must agree.
Error in untitled2 (line 16)
surf(Xg, Yg, Ug, 'edgecolor', 'none');
Walter Roberson
Walter Roberson 대략 24시간 전
Seems to work fine for me.
nodalPositions = rand(2, 100);
x=nodalPositions(1,:);
y=nodalPositions(2,:);
u = rand(1,100);
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');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Boundary Conditions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by