Plotting 3D graph
Show older comments
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?

Answers (1)
Star Strider
on 5 Feb 2021
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.
.
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!