Effacer les filtres
Effacer les filtres

Create 3D Surf from table of data

8 vues (au cours des 30 derniers jours)
Camila Gill
Camila Gill le 13 Avr 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);

Réponses (1)

Star Strider
Star Strider le 13 Avr 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)
.

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by