Plotting 3D graph
显示 更早的评论
I am trying to plot a surface graph based on coordinates for x,y and z (I have inserted the data below). So far I have only managed to use the surf function when z is a function of x and y, does anyone know how I would use my data to produe this graph?

回答(1 个)
Star Strider
2021-2-5
Try something like this:
D = readmatrix('YourDataFile.something');
N = 250;
xv = linspace(min(D(:,1)), max(D(:,1)), N);
yv = linspace(min(D(:,2)), max(D(:,2)), N);
[X,Y] = ndgrid(xv,yv);
Z = griddata(D(:,1), D(:,2),D(:,3),X,Y);
figure
surf(X, Y, Z)
shading('interp')
Make appropriate changes to get the result you want.
This should work, and griddata is quite robust, however there could be problems with your data (specifically NaN or Inf elements) that are currently not possible to determine.
.
类别
在 帮助中心 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!