3D Plotting in MATLAB

7 views (last 30 days)
Patrick Smith
Patrick Smith on 6 Oct 2019
Commented: Star Strider on 9 Oct 2019
How do I create a 3D surface plot of this data
Voltage 9
x 19 20 21 21 21 21 20 20 20 20 18
y 0 10 30 50 70 90 110 120 140 160 180
z 9 9 9 9 9 9 9 9 9 9 9
Voltage 8
x 37 38 38 38 37 37 36 38 37 35 35
y 0 10 30 50 70 90 110 120 140 160 180
z 8 8 8 8 8 8 8 8 8 8 8
Voltage 7
x 58 57 57 57 57 56 57 56 55 56 55
y 0 10 30 50 70 90 110 120 140 160 180
z 7 7 7 7 7 7 7 7 7 7 7
Voltage 6
x 77 78 77 77 77 77 77 78 76 76 76
y 0 10 30 50 70 90 110 120 140 160 180
z 7 7 7 7 7 7 7 7 7 7 7
Voltage 5
x 97 98 97 98 96 96 96 95 95 95 95
y 0 10 30 50 70 90 110 120 140 160 180
z 5 5 5 5 5 5 5 5 5 5 5
Voltage 3
x 137 137 138 139 139 140 140 139 139 140 140
y 0 10 30 50 70 90 110 120 140 160 180
z 3 3 3 3 3 3 3 3 3 3 3
Voltage 1
x 180 180 179 178 178 180 180 180 179 181 181
y 0 10 30 50 70 90 110 120 140 160 180
z 1 1 1 1 1 1 1 1 1 1 1
  5 Comments
Patrick Smith
Patrick Smith on 6 Oct 2019
The Z data is the voltages which are 9, 8, 7, 6 ,5, 3, 1
Star Strider
Star Strider on 9 Oct 2019
For what it’s worth —
% Voltage 9
x9 = [ 19 20 21 21 21 21 20 20 20 20 18 ];
y9 = [ 0 10 30 50 70 90 110 120 140 160 180 ];
z9 = [ 9 9 9 9 9 9 9 9 9 9 9 ];
% Voltage 8
x8 = [ 37 38 38 38 37 37 36 38 37 35 35 ];
y8 = [ 0 10 30 50 70 90 110 120 140 160 180 ];
z8 = [ 8 8 8 8 8 8 8 8 8 8 8 ];
% Voltage 7
x7 = [ 58 57 57 57 57 56 57 56 55 56 55 ];
y7 = [ 0 10 30 50 70 90 110 120 140 160 180 ];
z7 = [ 7 7 7 7 7 7 7 7 7 7 7 ];
% Voltage 6
x6 = [ 77 78 77 77 77 77 77 78 76 76 76 ];
y6 = [ 0 10 30 50 70 90 110 120 140 160 180 ];
z6 = [ 7 7 7 7 7 7 7 7 7 7 7 ]; % <— Should These Be ‘6’?
% Voltage 5
x5 = [ 97 98 97 98 96 96 96 95 95 95 95 ];
y5 = [ 0 10 30 50 70 90 110 120 140 160 180 ];
z5 = [ 5 5 5 5 5 5 5 5 5 5 5 ];
% Voltage 3
x3 = [ 137 137 138 139 139 140 140 139 139 140 140 ];
y3 = [ 0 10 30 50 70 90 110 120 140 160 180 ];
z3 = [ 3 3 3 3 3 3 3 3 3 3 3 ];
% Voltage 1
x1 =[ 180 180 179 178 178 180 180 180 179 181 181 ];
y1 = [ 0 10 30 50 70 90 110 120 140 160 180 ];
z1 = [ 1 1 1 1 1 1 1 1 1 1 1 ];
X = [x1; x3; x6; x7; x8; x9];
Y = [y1; y3; y6; y7; y8; y9];
Z = [z1; z3; z6; z7; z8; z9];
figure
surf(X, Y, Z)
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
view(30,30)
#3D Plotting in MATLAB.png

Sign in to comment.

Answers (1)

darova
darova on 6 Oct 2019
Use plot3()
% Voltage 9
x9 = [ 19 20 21 21 21 21 20 20 20 20 18 ];
y9 = [ 0 10 30 50 70 90 110 120 140 160 180 ];
%% ---------
% Voltage 1
x1 = [ 180 180 179 178 178 180 180 180 179 181 181];
y1 = [ 0 10 30 50 70 90 110 120 140 160 180];
x = [x9 x8 x7 x6 x5 x3 x1];
y = [y9 y8 y7 y6 y5 y3 y1];
z = [x9*0+9 x8*0+8 x7*0+7 x6*0+6 x5*0+5 x3*0+3 x1*0+1];
plot3(x,y,z,'.r')
Or you can use griddata
xx = linspace(min(x),max(x),20);
yy = linspace(min(y),max(y),20);
[X,Y] = meshgrid(xx,yy);
Z = griddata(x,y,z,X,Y);
surf(X,Y,Z)
  4 Comments
Patrick Smith
Patrick Smith on 7 Oct 2019
I don't know how to use surf and you deleted my last question which had all my data correctly organized. I need help getting the solution. Can you create the surface plot and explain to me how you did it and how it worked I am trying my best here. Example of the first point is (18,180,9) the next point would be (19,0,9) I have the values organized by variable but still in order.
X Values: 18 19 20 20 20 20 20 21 21 21 21 35 35 36 37 37 37 37 38 38 38 38 55 55 56 56 56 57 57 57 57 57 58 76 76 76 77 77 77 77 77 77 78 95 95 95 95 96 96 96 97 97 98 98 137 137 138 139 139 139 139 140 140 140 140 178 178 179 179 180 180 180 180 180 181 181
Y Values: 180 0 10 110 120 140 160 30 50 70 90 160 180 110 0 70 90 140 10 30 50 120 140 180 90 120 160 10 30 50 70 110 0 140 160 180 0 30 50 70 90 110 120 120 140 160 180 70 90 110 0 30 10 50 0 10 30 50 70 120 140 90 110 160 180 50 70 30 140 0 10 90 110 120 160 180
Z Values: 9 9 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 7 7 7 7 6 6 6 6 6 6 6 6 6 6 5 5 5 5 5 5 5 5 5 5 5 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1
Walter Roberson
Walter Roberson on 7 Oct 2019
x = [18 19 20 20 20 20 20 21 21 21 21 35 35 36 37 37 37 37 38 38 38 38 55 55 56 56 56 57 57 57 57 57 58 76 76 76 77 77 77 77 77 77 78 95 95 95 95 96 96 96 97 97 98 98 137 137 138 139 139 139 139 140 140 140 140 178 178 179 179 180 180 180 180 180 181 181 ];
y = [180 0 10 110 120 140 160 30 50 70 90 160 180 110 0 70 90 140 10 30 50 120 140 180 90 120 160 10 30 50 70 110 0 140 160 180 0 30 50 70 90 110 120 120 140 160 180 70 90 110 0 30 10 50 0 10 30 50 70 120 140 90 110 160 180 50 70 30 140 0 10 90 110 120 160 180 ];
z = [9 9 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 7 7 7 7 6 6 6 6 6 6 6 6 6 6 5 5 5 5 5 5 5 5 5 5 5 3 3 3 3 3 3 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1 1 ];
xx = linspace(min(x),max(x),20);
yy = linspace(min(y),max(y),20);
[X,Y] = meshgrid(xx,yy);
Z = griddata(x,y,z,X,Y);
surf(X,Y,Z, 'edgecolor', 'none')

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!