Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Plotting a sphere from a given x y z coordinates

Subject: Plotting a sphere from a given x y z coordinates

From: Geant Bepi

Date: 15 Jun, 2009 12:59:03

Message: 1 of 12

Hi guys,

I'm been tormented by this task for days now. Still I couldn't find the answer on the internet so I decided to post it here hoping that someone out there will be able to shed some light upon this dark path I'm in right now :)

I have a set of coordinates in three columns which describe a sphere. (let's say the file is mercury.txt)
now what I want is to load these data to matlab and make it understand these columns as x , y, z and generate a sphere accordingly.

When I simply do,
load mercury.txt
x1 = o(:,1)
y1 = o(:,2)
z1 = o(:,3)

and command to generate a sphere MATLAB says z should be a matrix not a vector.

in gnuplot I just use;
splot "mercury.txt" using 1:2:3 with lines title 'sphere'....

highly appreciate if someone can help me out..

Subject: Plotting a sphere from a given x y z coordinates

From: us

Date: 15 Jun, 2009 13:12:02

Message: 2 of 12

"Geant Bepi" <timothyschru@yahoo.co.uk> wrote in message <h15gim$1l7$1@fred.mathworks.com>...
> Hi guys,
>
> I'm been tormented by this task for days now. Still I couldn't find the answer on the internet so I decided to post it here hoping that someone out there will be able to shed some light upon this dark path I'm in right now :)
>
> I have a set of coordinates in three columns which describe a sphere. (let's say the file is mercury.txt)
> now what I want is to load these data to matlab and make it understand these columns as x , y, z and generate a sphere accordingly.
>
> When I simply do,
> load mercury.txt
> x1 = o(:,1)
> y1 = o(:,2)
> z1 = o(:,3)
>
> and command to generate a sphere MATLAB says z should be a matrix not a vector.
>
> in gnuplot I just use;
> splot "mercury.txt" using 1:2:3 with lines title 'sphere'....
>
> highly appreciate if someone can help me out..

a hint:

     help meshgrid;
     help ndgrid;

us

Subject: Plotting a sphere from a given x y z coordinates

From: Geant Bepi

Date: 16 Jun, 2009 08:26:02

Message: 3 of 12

"us " <us@neurol.unizh.ch> wrote in message <h15hb1$kll$1@fred.mathworks.com>...
> "Geant Bepi" <timothyschru@yahoo.co.uk> wrote in message <h15gim$1l7$1@fred.mathworks.com>...
> > Hi guys,
> >
> > I'm been tormented by this task for days now. Still I couldn't find the answer on the internet so I decided to post it here hoping that someone out there will be able to shed some light upon this dark path I'm in right now :)
> >
> > I have a set of coordinates in three columns which describe a sphere. (let's say the file is mercury.txt)
> > now what I want is to load these data to matlab and make it understand these columns as x , y, z and generate a sphere accordingly.
> >
> > When I simply do,
> > load mercury.txt
> > x1 = o(:,1)
> > y1 = o(:,2)
> > z1 = o(:,3)
> >
> > and command to generate a sphere MATLAB says z should be a matrix not a vector.
> >
> > in gnuplot I just use;
> > splot "mercury.txt" using 1:2:3 with lines title 'sphere'....
> >
> > highly appreciate if someone can help me out..
>
> a hint:
>
> help meshgrid;
> help ndgrid;
>
> us

Thanks us,
unfortunately so far no success. maybe I have not explained myself better..

Subject: Plotting a sphere from a given x y z coordinates

From: us

Date: 16 Jun, 2009 08:35:02

Message: 4 of 12

"Geant Bepi" <timothyschru@yahoo.co.uk> wrote in message <h17kuq$skm$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote in message <h15hb1$kll$1@fred.mathworks.com>...
> > "Geant Bepi" <timothyschru@yahoo.co.uk> wrote in message <h15gim$1l7$1@fred.mathworks.com>...
> > > Hi guys,
> > >
> > > I'm been tormented by this task for days now. Still I couldn't find the answer on the internet so I decided to post it here hoping that someone out there will be able to shed some light upon this dark path I'm in right now :)
> > >
> > > I have a set of coordinates in three columns which describe a sphere. (let's say the file is mercury.txt)
> > > now what I want is to load these data to matlab and make it understand these columns as x , y, z and generate a sphere accordingly.
> > >
> > > When I simply do,
> > > load mercury.txt
> > > x1 = o(:,1)
> > > y1 = o(:,2)
> > > z1 = o(:,3)
> > >
> > > and command to generate a sphere MATLAB says z should be a matrix not a vector.
> > >
> > > in gnuplot I just use;
> > > splot "mercury.txt" using 1:2:3 with lines title 'sphere'....
> > >
> > > highly appreciate if someone can help me out..
> >
> > a hint:
> >
> > help meshgrid;
> > help ndgrid;
> >
> > us
>
> Thanks us,
> unfortunately so far no success. maybe I have not explained myself better..

well, show what you've done so far with one of those functions...

us

Subject: Plotting a sphere from a given x y z coordinates

From: Geant Bepi

Date: 16 Jun, 2009 10:57:01

Message: 5 of 12

"us " <us@neurol.unizh.ch> wrote in message <h17lfm$3bk$1@fred.mathworks.com>...
> "Geant Bepi" <timothyschru@yahoo.co.uk> wrote in message <h17kuq$skm$1@fred.mathworks.com>...
> > "us " <us@neurol.unizh.ch> wrote in message <h15hb1$kll$1@fred.mathworks.com>...
> > > "Geant Bepi" <timothyschru@yahoo.co.uk> wrote in message <h15gim$1l7$1@fred.mathworks.com>...
> > > > Hi guys,
> > > >
> > > > I'm been tormented by this task for days now. Still I couldn't find the answer on the internet so I decided to post it here hoping that someone out there will be able to shed some light upon this dark path I'm in right now :)
> > > >
> > > > I have a set of coordinates in three columns which describe a sphere. (let's say the file is mercury.txt)
> > > > now what I want is to load these data to matlab and make it understand these columns as x , y, z and generate a sphere accordingly.
> > > >
> > > > When I simply do,
> > > > load mercury.txt
> > > > x1 = o(:,1)
> > > > y1 = o(:,2)
> > > > z1 = o(:,3)
> > > >
> > > > and command to generate a sphere MATLAB says z should be a matrix not a vector.
> > > >
> > > > in gnuplot I just use;
> > > > splot "mercury.txt" using 1:2:3 with lines title 'sphere'....
> > > >
> > > > highly appreciate if someone can help me out..
> > >
> > > a hint:
> > >
> > > help meshgrid;
> > > help ndgrid;
> > >
> > > us
> >
> > Thanks us,
> > unfortunately so far no success. maybe I have not explained myself better..
>
> well, show what you've done so far with one of those functions...
>
> us

clear all
load sphere.txt
x1 = sphere(:,1)
y1 = sphere(:,2)
z1 = sphere(:,3)
[X1,Y1,Z1] = ndgrid(x1,y1,z1);
surf(X1,Y1,Z1)

it gives this error. I dont know how to change it to what its asking..
>>
??? CData must be an M-by-N matrix or M-by-N-by-3 array.

Error in ==> surf at 97
    hh = double(graph3d.surfaceplot(args{:},'parent',parax));
>>

for e.g, my data looks like this
0.087 0.000 0.996

0.084 0.024 0.996
.
.
.
.
.>>

however, gnuplot generates my sphere with the same data.

Subject: Plotting a sphere from a given x y z coordinates

From: Geant Bepi

Date: 18 Jun, 2009 06:57:01

Message: 6 of 12

"Geant Bepi" <timothyschru_useonlywhatsbeforeunderscore@yahoo.co.uk> wrote in message <h17tpt$pti$1@fred.mathworks.com>...
> "us " <us@neurol.unizh.ch> wrote in message <h17lfm$3bk$1@fred.mathworks.com>...
> > "Geant Bepi" <timothyschru@yahoo.co.uk> wrote in message <h17kuq$skm$1@fred.mathworks.com>...
> > > "us " <us@neurol.unizh.ch> wrote in message <h15hb1$kll$1@fred.mathworks.com>...
> > > > "Geant Bepi" <timothyschru@yahoo.co.uk> wrote in message <h15gim$1l7$1@fred.mathworks.com>...
> > > > > Hi guys,
> > > > >
> > > > > I'm been tormented by this task for days now. Still I couldn't find the answer on the internet so I decided to post it here hoping that someone out there will be able to shed some light upon this dark path I'm in right now :)
> > > > >
> > > > > I have a set of coordinates in three columns which describe a sphere. (let's say the file is mercury.txt)
> > > > > now what I want is to load these data to matlab and make it understand these columns as x , y, z and generate a sphere accordingly.
> > > > >
> > > > > When I simply do,
> > > > > load mercury.txt
> > > > > x1 = o(:,1)
> > > > > y1 = o(:,2)
> > > > > z1 = o(:,3)
> > > > >
> > > > > and command to generate a sphere MATLAB says z should be a matrix not a vector.
> > > > >
> > > > > in gnuplot I just use;
> > > > > splot "mercury.txt" using 1:2:3 with lines title 'sphere'....
> > > > >
> > > > > highly appreciate if someone can help me out..
> > > >
> > > > a hint:
> > > >
> > > > help meshgrid;
> > > > help ndgrid;
> > > >
> > > > us
> > >
> > > Thanks us,
> > > unfortunately so far no success. maybe I have not explained myself better..
> >
> > well, show what you've done so far with one of those functions...
> >
> > us
>
> clear all
> load sphere.txt
> x1 = sphere(:,1)
> y1 = sphere(:,2)
> z1 = sphere(:,3)
> [X1,Y1,Z1] = ndgrid(x1,y1,z1);
> surf(X1,Y1,Z1)
>
> it gives this error. I dont know how to change it to what its asking..
> >>
> ??? CData must be an M-by-N matrix or M-by-N-by-3 array.
>
> Error in ==> surf at 97
> hh = double(graph3d.surfaceplot(args{:},'parent',parax));
> >>
>
> for e.g, my data looks like this
> 0.087 0.000 0.996
>
> 0.084 0.024 0.996
> .
> .
> .
> .
> .>>
>
> however, gnuplot generates my sphere with the same data.


I hope someone still would be able to help me.

I can get a very crude sphere from PLOT3(X,Y,Z) command.
I'd like to know if I can now generate a sphere with surface from these data..

Subject: Plotting a sphere from a given x y z coordinates

From: Luigi Giaccari

Date: 23 Jun, 2009 16:57:01

Message: 7 of 12

"Geant Bepi" <timothyschru@yahoo.co.uk> wrote in message <h15gim$1l7$1@fred.mathworks.com>...
> Hi guys,
>
> I'm been tormented by this task for days now. Still I couldn't find the answer on the internet so I decided to post it here hoping that someone out there will be able to shed some light upon this dark path I'm in right now :)
>
> I have a set of coordinates in three columns which describe a sphere. (let's say the file is mercury.txt)
> now what I want is to load these data to matlab and make it understand these columns as x , y, z and generate a sphere accordingly.
>
> When I simply do,
> load mercury.txt
> x1 = o(:,1)
> y1 = o(:,2)
> z1 = o(:,3)
>
> and command to generate a sphere MATLAB says z should be a matrix not a vector.


http://giaccariluigi.altervista.org/blog/

http://www.mathworks.com/matlabcentral/fileexchange/22185

http://www.mathworks.com/matlabcentral/fileexchange/22595

http://www.mathworks.com/matlabcentral/fileexchange/23447

These tools are for non convex surfaces
SInce your sphere is convex you can use the convhulln function to tesselate the points and then the trisurf command to plot the surface.

Regards Luigi
>
> in gnuplot I just use;
> splot "mercury.txt" using 1:2:3 with lines title 'sphere'....
>
> highly appreciate if someone can help me out..

Subject: Plotting a sphere from a given x y z coordinates

From: Geant Bepi

Date: 25 Jun, 2009 08:07:00

Message: 8 of 12

"Luigi Giaccari" <giaccariluigi@msn.com> wrote in message <h1r1gt$dqu$1@fred.mathworks.com>...
> "Geant Bepi" <timothyschru@yahoo.co.uk> wrote in message <h15gim$1l7$1@fred.mathworks.com>...
> > Hi guys,
> >
> > I'm been tormented by this task for days now. Still I couldn't find the answer on the internet so I decided to post it here hoping that someone out there will be able to shed some light upon this dark path I'm in right now :)
> >
> > I have a set of coordinates in three columns which describe a sphere. (let's say the file is mercury.txt)
> > now what I want is to load these data to matlab and make it understand these columns as x , y, z and generate a sphere accordingly.
> >
> > When I simply do,
> > load mercury.txt
> > x1 = o(:,1)
> > y1 = o(:,2)
> > z1 = o(:,3)
> >
> > and command to generate a sphere MATLAB says z should be a matrix not a vector.
>
>
> http://giaccariluigi.altervista.org/blog/
>
> http://www.mathworks.com/matlabcentral/fileexchange/22185
>
> http://www.mathworks.com/matlabcentral/fileexchange/22595
>
> http://www.mathworks.com/matlabcentral/fileexchange/23447
>
> These tools are for non convex surfaces
> SInce your sphere is convex you can use the convhulln function to tesselate the points and then the trisurf command to plot the surface.
>
> Regards Luigi
> >
> > in gnuplot I just use;
> > splot "mercury.txt" using 1:2:3 with lines title 'sphere'....
> >
> > highly appreciate if someone can help me out..


Hey Luigi!

great stuff. it worked! thank you so much.
I couldnt believe my eyes when Matlab produced the sphere that I was so longing for with simple two lines of convhulln and trisurf..

you see I'm quite new to matlab and I'm starting to love it!!

I researched to see if I can find a way to 'hide' the lines of the triangles created by convhulln on the sphere but failed.
I tried 'patch' as well but still the lines wont go away..

anyways, even with the lines I'm happy!

Subject: Plotting a sphere from a given x y z coordinates

From: John D'Errico

Date: 25 Jun, 2009 10:40:18

Message: 9 of 12

"Geant Bepi" <timothyschru_useonlywhatsbeforeunderscore@yahoo.co.uk> wrote in message <h1vb74$hrc$1@fred.mathworks.com>...
> "Luigi Giaccari" <giaccariluigi@msn.com> wrote in message <h1r1gt$dqu$1@fred.mathworks.com>...
> > "Geant Bepi" <timothyschru@yahoo.co.uk> wrote in message <h15gim$1l7$1@fred.mathworks.com>...
> > > Hi guys,
> > >
> > > I'm been tormented by this task for days now. Still I couldn't find the answer on the internet so I decided to post it here hoping that someone out there will be able to shed some light upon this dark path I'm in right now :)
> > >
> > > I have a set of coordinates in three columns which describe a sphere. (let's say the file is mercury.txt)
> > > now what I want is to load these data to matlab and make it understand these columns as x , y, z and generate a sphere accordingly.
> > >
> > > When I simply do,
> > > load mercury.txt
> > > x1 = o(:,1)
> > > y1 = o(:,2)
> > > z1 = o(:,3)
> > >
> > > and command to generate a sphere MATLAB says z should be a matrix not a vector.
> >
> >
> > http://giaccariluigi.altervista.org/blog/
> >
> > http://www.mathworks.com/matlabcentral/fileexchange/22185
> >
> > http://www.mathworks.com/matlabcentral/fileexchange/22595
> >
> > http://www.mathworks.com/matlabcentral/fileexchange/23447
> >
> > These tools are for non convex surfaces
> > SInce your sphere is convex you can use the convhulln function to tesselate the points and then the trisurf command to plot the surface.
> >
> > Regards Luigi
> > >
> > > in gnuplot I just use;
> > > splot "mercury.txt" using 1:2:3 with lines title 'sphere'....
> > >
> > > highly appreciate if someone can help me out..
>
>
> Hey Luigi!
>
> great stuff. it worked! thank you so much.
> I couldnt believe my eyes when Matlab produced the sphere that I was so longing for with simple two lines of convhulln and trisurf..
>
> you see I'm quite new to matlab and I'm starting to love it!!
>
> I researched to see if I can find a way to 'hide' the lines of the triangles created by convhulln on the sphere but failed.
> I tried 'patch' as well but still the lines wont go away..
>
> anyways, even with the lines I'm happy!

The simplest way to make the lines go away is

   shading interp

Another option is to return a handle from trisurf.

   h = trisurf(...)
   set(h,'edgecolor','none');

John

Subject: Plotting a sphere from a given x y z coordinates

From: Geant Bepi

Date: 26 Jun, 2009 07:28:01

Message: 10 of 12

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <h1vk6i$b0g$1@fred.mathworks.com>...

>
> The simplest way to make the lines go away is
>
> shading interp
>
> Another option is to return a handle from trisurf.
>
> h = trisurf(...)
> set(h,'edgecolor','none');
>
> John


oh yeah, that works.. now it looks pretty neat!

Subject: Plotting a sphere from a given x y z coordinates

From: Zereen

Date: 2 Aug, 2011 19:30:11

Message: 11 of 12

"Geant Bepi" wrote in message <h21ta0$9dp$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <h1vk6i$b0g$1@fred.mathworks.com>...
>
> >
> > The simplest way to make the lines go away is
> >
> > shading interp
> >
> > Another option is to return a handle from trisurf.
> >
> > h = trisurf(...)
> > set(h,'edgecolor','none');
> >
> > John
>
>
> oh yeah, that works.. now it looks pretty neat!

Hi, those links are not working anymore and I am having the same problem. So, can you please provide me with your code or any kind of help?

Thax.

Subject: Plotting a sphere from a given x y z coordinates

From: Abhinendra

Date: 9 Aug, 2011 11:40:31

Message: 12 of 12

Hi Zereen,
Did you get any help or were you able to solve the problem.
The help would be highly appreciated.
Thanks
"Zereen" wrote in message <j19j83$432$1@newscl01ah.mathworks.com>...
> "Geant Bepi" wrote in message <h21ta0$9dp$1@fred.mathworks.com>...
> > "John D'Errico" <woodchips@rochester.rr.com> wrote in message <h1vk6i$b0g$1@fred.mathworks.com>...
> >
> > >
> > > The simplest way to make the lines go away is
> > >
> > > shading interp
> > >
> > > Another option is to return a handle from trisurf.
> > >
> > > h = trisurf(...)
> > > set(h,'edgecolor','none');
> > >
> > > John
> >
> >
> > oh yeah, that works.. now it looks pretty neat!
>
> Hi, those links are not working anymore and I am having the same problem. So, can you please provide me with your code or any kind of help?
>
> Thax.

Tags for this Thread

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.

Contact us