how can i make a surf from 36 points?
5 views (last 30 days)
Show older comments
I've 36 points with a height.
X Y Z
2 2 0.5
2 4 1
2 6 1.5
2 8 2
2 10 2.5
2 12 3
4 2 0.5
4 4 1
4 6 1.5
4 8 2
4 10 2.5
4 12 3
6 2 0.5
6 4 1
6 6 1.5
6 8 2
6 10 2.5
6 12 3
8 2 0.5
8 4 1
8 6 1.5
8 8 2
8 10 2.5
8 12 3
10 2 0.5
10 4 1
10 6 1.5
10 8 2
10 10 2.5
10 12 3
12 2 0.5
12 4 1
12 6 1.5
12 8 2
12 10 2.5
12 12 3
Now i want to make a surf(3D) but, i get a error. Z must be a matrix, not a scalar or vector.
what function should I use?
Thank you
0 Comments
Answers (2)
Adam
on 27 Feb 2015
You need to use meshgrid:
doc meshgrid
to create outputs of the right dimensionality
Joseph Cheng
on 27 Feb 2015
Edited: Joseph Cheng
on 27 Feb 2015
since its nicely ordered and evenly spaced then you can reshape Z vector to
z = reshape(Z,6,6);
along with
[x,y]=meshgrid(2:2:12,2:2:12)
then surf(x,y,z).
as i did it quickly i'd double check that the reshaping of the Z column matches up with the meshgrid of x and y. other wise if i got it mixed up then its reshape()' which will be the transpose.
2 Comments
Joseph Cheng
on 27 Feb 2015
yes... it still has a grid pattern to it. if it doesn't you'd probably want to use interp2 to fill in between. if you do not want to hard code in the grid then you can also do this
x = reshape(example(:,1),6,6)
y = reshape(example(:,2),6,6)
z = reshape(example(:,3),6,6)
figure,surf(x,y,z)
where example is your table above
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!