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

Réponses (2)

Adam
Adam le 27 Fév 2015
You need to use meshgrid:
doc meshgrid
to create outputs of the right dimensionality

1 commentaire

Dominique Andriessen
Dominique Andriessen le 27 Fév 2015
yes i have done that but, than i get the error: Z must be a matrix, not a scalar or vector.

Connectez-vous pour commenter.

Joseph Cheng
Joseph Cheng le 27 Fév 2015
Modifié(e) : Joseph Cheng le 27 Fév 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 commentaires

Joseph Cheng is it also possible with these numbers?
Thank you
X Y Z
148431.000 459486.000 2.540
148431.000 459506.000 2.610
148431.000 459526.000 2.660
148431.000 459546.000 2.700
148431.000 459566.000 1.650
148431.000 459586.000 2.300
148451.000 459486.000 2.600
148451.000 459506.000 2.550
148451.000 459526.000 2.590
148451.000 459546.000 2.630
148451.000 459566.000 1.440
148451.000 459586.000 1.500
148471.000 459486.000 2.400
148471.000 459506.000 2.710
148471.000 459526.000 2.480
148471.000 459546.000 2.320
148471.000 459566.000 2.500
148471.000 459586.000 2.500
148491.000 459486.000 2.690
148491.000 459506.000 2.170
148491.000 459526.000 2.630
148491.000 459546.000 1.600
148491.000 459566.000 2.800
148491.000 459586.000 2.690
148511.000 459486.000 2.310
148511.000 459506.000 2.390
148511.000 459526.000 1.570
148511.000 459546.000 1.730
148511.000 459566.000 2.900
148511.000 459586.000 2.880
148531.000 459486.000 2.700
148531.000 459506.000 2.000
148531.000 459526.000 1.620
148531.000 459546.000 1.690
148531.000 459566.000 2.450
148531.000 459586.000 2.700
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

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by