Create 3D Surf from table of data

2 次查看(过去 30 天)
Given data attached:
I am trying to create a 3D plot using 'surf' command. Here is my own attempt at the code:
x = trainingdata(:,1);
y = trainingdata(:,2);
[X,Y] = meshgrid(x,y);
z = trainingdata(:,3);
figure(1)
surf(X,Y,z);
Need matrices that are at least 18x18 in size.
I am having trouble with the 'z' term. I am not able to plot it because I don't understand how to format the 'z' matrix. This is the error message shown:
Error using surf (line 71)
Z must be a matrix, not a scalar or vector
Error in fdm_nn_CGill (line 65)
surf(X,Y,z);

回答(1 个)

Star Strider
Star Strider 2020-4-13
The data are gridded, so you simply need to use the reshape function to create matrices from them:
[~,ix] = unique(trainingdata(:,1));
rc = mean(diff(ix));
X = reshape(trainingdata(:,1),rc,[]);
Y = reshape(trainingdata(:,2),rc,[]);
Z = reshape(trainingdata(:,3),rc,[]);
figure
surf(layerthick, speed, Z)
grid on
xlabel('Layer Thickness')
ylabel('Speed')
zlabel('Dependent Variable')
view(50,30)
.

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by