3d plot from knows XYZ

조회 수: 5 (최근 30일)
May
May 2023년 2월 26일
댓글: Star Strider 2023년 2월 26일
Hello, i have known list of numbers:
x = [0 10 20 30 0 10 20 0 10 20 30];
y = [0 0 0 0 15 15 15 15 30 30 30 30];
t = [20 22 25 23 22 27 30 25 19 20 18 22];
I used: [X,Y] = meshgrid(x,y), but i'm struggeling with understanding what to do with those t values.
thank you

답변 (2개)

Star Strider
Star Strider 2023년 2월 26일
편집: Star Strider 2023년 2월 26일
It will be necessary to interpolate them to create a surface.
There are seeral ways to interpolate them, my favourite being the scatteredInterpolant function.
Try something like this —
x = [0 10 20 30 0 10 20 0 10 20 30];
y = [0 0 0 0 15 15 15 15 30 30 30 30];
t = [20 22 25 23 22 27 30 25 19 20 18 22];
Q = [size(x); size(y); size(t)]
Q = 3×2
1 11 1 12 1 12
y = y(1:numel(x));
t = t(1:numel(x));
xv = linspace(min(x), max(x), numel(x));
yv = linspace(min(y), max(y), numel(y));
[X,Y] = meshgrid(xv,yv);
F = scatteredInterpolant(x(:),y(:),t(:));
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
T = F(X,Y);
figure
surfc(X, Y, T)
colormap(turbo)
colorbar
xlabel('X')
ylabel('Y')
zlabel('T')
EDIT — Added axis labels.
.
  댓글 수: 2
Walter Roberson
Walter Roberson 2023년 2월 26일
Note: the duplicate point is because the middle "30" is missing in x, so the 0 of the next x cycle lines up with the 15 of the end of the existing y cycle
0 10 20 0
15 15 15 15
whereas if the 30 had not been missed then it would have been (30,15) for that point instead of a second (0,15)
Star Strider
Star Strider 2023년 2월 26일
@Walter Roberson — That is also likely the origin of the vectors not having equal lengths. I just went with the available data.
I’m also assuming that May wants a surf plot because of the meshgrid call.

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


Devargya chakraborty
Devargya chakraborty 2023년 2월 26일
first of all, your vectors should be of the same length.
after that you can use the plot3 command to plot the graph or meshgrid also.
plot3(x,y,t);
meshgrid(x,y,t);

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by