Filter löschen
Filter löschen

Create 3D Surf from table of data

8 Ansichten (letzte 30 Tage)
Camila Gill
Camila Gill am 13 Apr. 2020
Beantwortet: Star Strider am 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);

Antworten (1)

Star Strider
Star Strider am 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)
.

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by