Thread Subject: How to surface-plot a series of points?

Subject: How to surface-plot a series of points?

From: Gyusok

Date: 12 Jan, 2009 21:06:02

Message: 1 of 8

Hello,

I am Matlab user with little experience. Probably this question is pretty easy for most of you, but I did not find any solution:
I have a matrix with n-rows and three columns that represent the 3-dimensional kartesian coordinates of n-surface points obtained by loading a data file.
These points I want to visualise as a surface, not just as points in a Figure.

The Matrix is as follows:
              x y z
Points = 1.2360 25.4359 38.3812
            0.9510 25.4896 36.9742
            0.6072 25.5178 35.5796
            0.0600 25.5160 33.7439
            -0.4068 25.4894 32.3855
            -0.9237 25.4400 31.0457
            -1.6916 25.3376 29.2938
            1.2063 24.6046 37.1182
            0.9283 24.7229 35.8329
            0.5895 24.8152 34.5606
            0.0527 24.9007 32.8865
           -0.4075 24.9381 31.6487
           -0.9146 24.9552 30.4301
etc....

I want to plot the information in the matrix as a surface and not as it is possible using the plot3 command as points. I tried to use the mesh and surf command but did not succed to display a decent visualisation in a figure window.


Thank you very much for your help.

  Gyusok

Subject: How to surface-plot a series of points?

From: someone

Date: 12 Jan, 2009 21:20:17

Message: 2 of 8

"Gyusok " <gyusok@gmail.com> wrote in message <gkgbbq$r0o$1@fred.mathworks.com>...
> Hello,
>
> I am Matlab user with little experience. Probably this question is pretty easy for most of you, but I did not find any solution:
> I have a matrix with n-rows and three columns that represent the 3-dimensional kartesian coordinates of n-surface points obtained by loading a data file.
> These points I want to visualise as a surface, not just as points in a Figure.
>
> The Matrix is as follows:
> x y z
> Points = 1.2360 25.4359 38.3812
> 0.9510 25.4896 36.9742
> 0.6072 25.5178 35.5796
> 0.0600 25.5160 33.7439
> -0.4068 25.4894 32.3855
> -0.9237 25.4400 31.0457
> -1.6916 25.3376 29.2938
> 1.2063 24.6046 37.1182
> 0.9283 24.7229 35.8329
> 0.5895 24.8152 34.5606
> 0.0527 24.9007 32.8865
> -0.4075 24.9381 31.6487
> -0.9146 24.9552 30.4301
> etc....
>
> I want to plot the information in the matrix as a surface and not as it is possible using the plot3 command as points. I tried to use the mesh and surf command but did not succed to display a decent visualisation in a figure window.
>
>
> Thank you very much for your help.
>
> Gyusok

% a simple solution that should work:

x = Points(:,1);
y = Points(:,2);
z = Points(:,3);

surf(x,y,z)

% or simply:

surf(Points(:,1),Points(:,2),Points(:,3))

% no need for meshgrid

Subject: How to surface-plot a series of points?

From: Gyusok

Date: 12 Jan, 2009 22:05:05

Message: 3 of 8

Thank you very much for your help, but it did not work since it seems that Matlab requires z to be an (n,m) matrix (from the Matlab-help)

// ??? Error using ==> surf at 70
// Z must be a matrix, not a scalar or vector.


surf(x,y,z)
while dim(x)=n and dim(y)=m.
I could arrange all entries of the z-coloumn on the principal axis of a matrix 'z' but this would lead to many points with a value of zero to be surface-plotted.

Any other idea?
Thank you,

Gyusok

> % a simple solution that should work:
>
> x = Points(:,1);
> y = Points(:,2);
> z = Points(:,3);
>
> surf(x,y,z)
>
> % or simply:
>
> surf(Points(:,1),Points(:,2),Points(:,3))
>
> % no need for meshgrid

Subject: How to surface-plot a series of points?

From: someone

Date: 12 Jan, 2009 22:47:01

Message: 4 of 8

"Gyusok " <gyusok@gmail.com> wrote in message <gkgeqh$j22$1@fred.mathworks.com>...
> Thank you very much for your help, but it did not work since it seems that Matlab requires z to be an (n,m) matrix (from the Matlab-help)
>
> // ??? Error using ==> surf at 70
> // Z must be a matrix, not a scalar or vector.
>
>
> surf(x,y,z)
> while dim(x)=n and dim(y)=m.
> I could arrange all entries of the z-coloumn on the principal axis of a matrix 'z' but this would lead to many points with a value of zero to be surface-plotted.
>
> Any other idea?
> Thank you,
>
> Gyusok
>
> > % a simple solution that should work:
> >
> > x = Points(:,1);
> > y = Points(:,2);
> > z = Points(:,3);
> >
> > surf(x,y,z)
> >
> > % or simply:
> >
> > surf(Points(:,1),Points(:,2),Points(:,3))
> >
> > % no need for meshgrid
>
>
% Sorry, misread the documentation.
% Not sure if this is what you want, but try:

oints = [1.2360 25.4359 38.3812;
0.9510 25.4896 36.9742;
 0.6072 25.5178 35.5796;
 0.0600 25.5160 33.7439;
 -0.4068 25.4894 32.3855;
 -0.9237 25.4400 31.0457;
-1.6916 25.3376 29.2938;
 1.2063 24.6046 37.1182;
 0.9283 24.7229 35.8329;
 0.5895 24.8152 34.5606;
 0.0527 24.9007 32.8865;
 -0.4075 24.9381 31.6487;
 -0.9146 24.9552 30.4301] % etc ...

x = Points(:,1);
y = Points(:,2);
z = Points(:,3);

Z = repmat(z,1,13);

surf(x,y,Z)

Subject: How to surface-plot a series of points?

From: someone

Date: 12 Jan, 2009 22:50:19

Message: 5 of 8

"Gyusok " <gyusok@gmail.com> wrote in message <gkgeqh$j22$1@fred.mathworks.com>...
> Thank you very much for your help, but it did not work since it seems that Matlab requires z to be an (n,m) matrix (from the Matlab-help)
>

% To generalize my last post, let:

Z = repmat(z,1,length(z));

Subject: How to surface-plot a series of points?

From: Andrew McGillis

Date: 12 Jan, 2009 23:34:01

Message: 6 of 8

"Gyusok " <gyusok@gmail.com> wrote in message <gkgbbq$r0o$1@fred.mathworks.com>...
> Hello,
>
> I am Matlab user with little experience. Probably this question is pretty easy for most of you, but I did not find any solution:
> I have a matrix with n-rows and three columns that represent the 3-dimensional kartesian coordinates of n-surface points obtained by loading a data file.
> These points I want to visualise as a surface, not just as points in a Figure.
>
> The Matrix is as follows:
> x y z
> Points = 1.2360 25.4359 38.3812
> 0.9510 25.4896 36.9742
> 0.6072 25.5178 35.5796
> 0.0600 25.5160 33.7439
> -0.4068 25.4894 32.3855
> -0.9237 25.4400 31.0457
> -1.6916 25.3376 29.2938
> 1.2063 24.6046 37.1182
> 0.9283 24.7229 35.8329
> 0.5895 24.8152 34.5606
> 0.0527 24.9007 32.8865
> -0.4075 24.9381 31.6487
> -0.9146 24.9552 30.4301
> etc....
>
> I want to plot the information in the matrix as a surface and not as it is possible using the plot3 command as points. I tried to use the mesh and surf command but did not succed to display a decent visualisation in a figure window.
>
>
> Thank you very much for your help.
>
> Gyusok

If your data is not evenly spaced in x and y, you will need to make a mesh, then interpolate it to the mesh using griddata (or JE's gridfit)

You might try:
% copy-paste from here down------------------

x=Points(:,1);
y=Points(:,2);
z=Points(:,3);

dx=1;
dy=1;

x_edge=[floor(min(x)):dx:ceil(max(x))];
y_edge=[floor(min(y)):dy:ceil(max(y))];
[X,Y]=meshgrid(x_edge,y_edge);
Z=griddata(x,y,z,X,Y);
% The following line of code is if you use JE's gridfit:
% Z=gridfit(x,y,z,x_edge,y_edge);

%NOW surf and mesh will work...

surf(X,Y,Z)
%mesh(X,Y,Z)

%End of code to be copied-----------------------


Cheers,
Andrew

Subject: How to surface-plot a series of points?

From: Gyusok

Date: 13 Jan, 2009 10:34:01

Message: 7 of 8

"Andrew McGillis" <amcgillisREMOVE@rogers.com> wrote in message <gkgk19$14g$1@fred.mathworks.com>...
> "Gyusok " <gyusok@gmail.com> wrote in message <gkgbbq$r0o$1@fred.mathworks.com>...
> > Hello,
> >
> > I am Matlab user with little experience. Probably this question is pretty easy for most of you, but I did not find any solution:
> > I have a matrix with n-rows and three columns that represent the 3-dimensional kartesian coordinates of n-surface points obtained by loading a data file.
> > These points I want to visualise as a surface, not just as points in a Figure.
> >
> > The Matrix is as follows:
> > x y z
> > Points = 1.2360 25.4359 38.3812
> > 0.9510 25.4896 36.9742
> > 0.6072 25.5178 35.5796
> > 0.0600 25.5160 33.7439
> > -0.4068 25.4894 32.3855
> > -0.9237 25.4400 31.0457
> > -1.6916 25.3376 29.2938
> > 1.2063 24.6046 37.1182
> > 0.9283 24.7229 35.8329
> > 0.5895 24.8152 34.5606
> > 0.0527 24.9007 32.8865
> > -0.4075 24.9381 31.6487
> > -0.9146 24.9552 30.4301
> > etc....
> >
> > I want to plot the information in the matrix as a surface and not as it is possible using the plot3 command as points. I tried to use the mesh and surf command but did not succed to display a decent visualisation in a figure window.
> >
> >
> > Thank you very much for your help.
> >
> > Gyusok
>
> If your data is not evenly spaced in x and y, you will need to make a mesh, then interpolate it to the mesh using griddata (or JE's gridfit)
>
> You might try:
> % copy-paste from here down------------------
>
> x=Points(:,1);
> y=Points(:,2);
> z=Points(:,3);
>
> dx=1;
> dy=1;
> x_edge=[floor(min(x)):dx:ceil(max(x))];
> y_edge=[floor(min(y)):dy:ceil(max(y))];
> [X,Y]=meshgrid(x_edge,y_edge);
> Z=griddata(x,y,z,X,Y);
> % The following line of code is if you use JE's gridfit:
> % Z=gridfit(x,y,z,x_edge,y_edge);
> %NOW surf and mesh will work...
> surf(X,Y,Z)
> %mesh(X,Y,Z)
> %End of code to be copied-----------------------
> Cheers,
> Andrew


Thank you very much Andrew,
it works perfectly when reducing dx, dy to increase the resolution. (?)

Cheers,

Gyusok

Subject: How to surface-plot a series of points?

From: Fivos

Date: 1 Jul, 2010 09:03:06

Message: 8 of 8

"Andrew McGillis" <amcgillisREMOVE@rogers.com> wrote in message <gkgk19$14g$1@fred.mathworks.com>...
> "Gyusok " <gyusok@gmail.com> wrote in message <gkgbbq$r0o$1@fred.mathworks.com>...
> > Hello,
> >
> > I am Matlab user with little experience. Probably this question is pretty easy for most of you, but I did not find any solution:
> > I have a matrix with n-rows and three columns that represent the 3-dimensional kartesian coordinates of n-surface points obtained by loading a data file.
> > These points I want to visualise as a surface, not just as points in a Figure.
> >
> > The Matrix is as follows:
> > x y z
> > Points = 1.2360 25.4359 38.3812
> > 0.9510 25.4896 36.9742
> > 0.6072 25.5178 35.5796
> > 0.0600 25.5160 33.7439
> > -0.4068 25.4894 32.3855
> > -0.9237 25.4400 31.0457
> > -1.6916 25.3376 29.2938
> > 1.2063 24.6046 37.1182
> > 0.9283 24.7229 35.8329
> > 0.5895 24.8152 34.5606
> > 0.0527 24.9007 32.8865
> > -0.4075 24.9381 31.6487
> > -0.9146 24.9552 30.4301
> > etc....
> >
> > I want to plot the information in the matrix as a surface and not as it is possible using the plot3 command as points. I tried to use the mesh and surf command but did not succed to display a decent visualisation in a figure window.
> >
> >
> > Thank you very much for your help.
> >
> > Gyusok
>
> If your data is not evenly spaced in x and y, you will need to make a mesh, then interpolate it to the mesh using griddata (or JE's gridfit)
>
> You might try:
> % copy-paste from here down------------------
>
> x=Points(:,1);
> y=Points(:,2);
> z=Points(:,3);
>
> dx=1;
> dy=1;
>
> x_edge=[floor(min(x)):dx:ceil(max(x))];
> y_edge=[floor(min(y)):dy:ceil(max(y))];
> [X,Y]=meshgrid(x_edge,y_edge);
> Z=griddata(x,y,z,X,Y);
> % The following line of code is if you use JE's gridfit:
> % Z=gridfit(x,y,z,x_edge,y_edge);
>
> %NOW surf and mesh will work...
>
> surf(X,Y,Z)
> %mesh(X,Y,Z)
>
> %End of code to be copied-----------------------
>
>
> Cheers,
> Andrew

Thanks a ton , this post helped me a lot ! Also note that instead of Z=griddata(x,y,z,X,Y); you can use

F = TriScatteredInterp(x,y,z);
Z= F(X,Y);

which is better according to
http://blogs.mathworks.com/loren/2009/07/22/computational-geometry-in-matlab-r2009a-part-ii/

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
plot Gyusok 12 Jan, 2009 16:10:07
surface Gyusok 12 Jan, 2009 16:10:07
surf Gyusok 12 Jan, 2009 16:10:07
mesh Gyusok 12 Jan, 2009 16:10:07
plot3 Gyusok 12 Jan, 2009 16:10:07
rssFeed for this Thread

Contact us at files@mathworks.com