MATLAB Answers

creating 3D mesh for some points in space

185 views (last 30 days)
lala
lala on 10 Feb 2013
Answered: Jaco Verster on 6 Jul 2017
So I have these points, A, B, C, ... in 3D. Their coordinates are denoted by x, y, z. For example point A has these coordinates: if x=2.5 and y=12, then z is 3, and B is x=4, y=3, and z=15; and so on.
So i created three arrays to show my points:
x=[2.5 4 6 18 9]; y=[12 3 7.5 1 10]; z=[3 15 16 8 11.5];
and i want to create a 3D mesh from my points (A, B, ...). There are total of 9 points.
I am able to create plot3 and/or scatter3 but not mesh :(
Ive spent already a full week on this and read many tutorials and such but i just get more confused and dont get it. Please help! Thanks!
lala-
  1 Comment
Kaixiang Wang
Kaixiang Wang on 30 Jan 2017
A mesh for only nine points? And z is not a function of x and y? What sort of visual result are you expecting?

Sign in to comment.

Answers (8)

Patrick Kalita
Patrick Kalita on 13 Feb 2013
trimesh is probably what you want to use. You can also use delaunay to generate the triangulation matrix that trimesh requires.
x=[2.5 4 6 18 9];
y=[12 3 7.5 1 10];
z=[3 15 16 8 11.5];
tri = delaunay(x, y);
trimesh(tri, x, y, z);
  1 Comment
lala
lala on 18 Feb 2013
Thanks. This is good but i think a smoother sruface like like surface mesh is what im looking for. Something to show at x and y coordinates, what is the z (distance.) I have about 9 z distances and basically want to find a good visual way. But thanks again.
L-

Sign in to comment.


Azzi Abdelmalek
Azzi Abdelmalek on 10 Feb 2013
Edited: Azzi Abdelmalek on 10 Feb 2013
You can't use mesh with your data. You will need more data. for example
x=[2.5 4 6 18 9];
y=[12 3 7.5 1 10];
[X,Y]=meshgrid(x,y)
% and for example
Z=X+Y
mesh(X,Y,Z)
% To understand, to create a mush plot with x=[1 2], and y=[ 10 20], you need
x=1,y=10
x=1,y=20,
x=2,y=10,
x=2,y=20
%to obtain these combinations we use
x=[1 2],
y=[ 10 20]
[X,Y]=meshgrid(x,y)
% find the corresponding z to each point
Z=cos(X+Y) % for example
mesh(X,Y,Z)
  1 Comment
lala
lala on 18 Feb 2013
Thanks for explanation. But since my Z is not a function of X and Y, i guess mesh and meshgrid could not be useful.

Sign in to comment.


Walter Roberson
Walter Roberson on 11 Feb 2013
Use griddata() or TriScatteredInterp to interpolate a grid of data from your points; then you can create a mesh from that.
Or you may wish to create a trimesh() once you have done a triangulation.

Parker Hinton
Parker Hinton on 26 May 2017
Yes all, there is a solution, it has been stated. "Use griddata() or TriScatteredInterp to interpolate a grid of data from your points; then you can create a mesh from that."

Benoit Botton
Benoit Botton on 4 Dec 2014
Lala,
did you ever find a solution? I have the same issue

Bhuvan Varugu
Bhuvan Varugu on 14 Apr 2015
I have the same issue. Please share some knowledge on this if you can?

fauer781
fauer781 on 7 Jan 2017
Hi, I am in the same situation. Is there a solution?

Jaco Verster
Jaco Verster on 6 Jul 2017
I had a similar problem - found a great solution here: https://www.mathworks.com/matlabcentral/fileexchange/8998-surface-fitting-using-gridfit

Community Treasure Hunt

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

Start Hunting!