Azzera filtri
Azzera filtri

Create 3D Surf from table of data

8 visualizzazioni (ultimi 30 giorni)
Camila Gill
Camila Gill il 13 Apr 2020
Risposto: Star Strider il 13 Apr 2020
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);

Risposte (1)

Star Strider
Star Strider il 13 Apr 2020
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)
.

Categorie

Scopri di più su Data Distribution Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by