Thread Subject: How to plot a 3d color graph with a cloud of data?

Subject: How to plot a 3d color graph with a cloud of data?

From: sharmin shamsalsadati

Date: 9 Nov, 2009 17:14:04

Message: 1 of 8

 I have 4 vectors , three of them are each points coordinates(x,y,z) with 200,000 element each. The fourth vector (c) is the same size of other vectors. I want to have a 3d plot which x(i),y(i),z(i) specifies each point's location and c(i) would be the color correspond to each point. I tried scatter3 but it doesn't give me a good plot since my data locations are too close to each other inside the volume and also I want to have interpolation between the data. So, it would be a colorful cube which color in each point shows the related magnitude in "c" vector. I also tried "slice" command to have color faces in the cube but it doesn't plot it ,because my "c" is not a 3d matrix and is not specified as a function of coordinates and my coordinates are not specified by meshgrid and don’t have a specific trend, couldn’t use the patch, either (lots of data with no pattern). Could you
please help me on how to do that and what are the options to have such a cube(having the magnitude inside the volume is preferred than just having it on its surface)?

Subject: How to plot a 3d color graph with a cloud of data?

From: Damian Sheehy

Date: 9 Nov, 2009 18:46:09

Message: 2 of 8

Hi Sharmin,

You can convert your data into a mesh grid using scattered data
interpolation.

If you have release R2009a or later
help TriScatteredInterp

otherwise
help griddata3

Here's an example using TriScatteredInterp.

% I will create sample data (x,y,z,v)
x = 2*rand(5000,1)-1;
y = 2*rand(5000,1)-1;
z = 2*rand(5000,1)-1;
v = x.^2 + y.^2 + z.^2;

% Construct an interpolant from the sample data
F = TriScatteredInterp(x,y,z,v)


% Create a mesh grid and query the interpolant at those points
d = -0.8:0.05:0.8;
[xi,yi,zi] = meshgrid(d,d,d);
vi = F(xi,yi,zi);

You now have a regular grid defined by (xi,yi,zi,vi) which you can slice.

Best regards,

Damian

"sharmin shamsalsadati" <sharmin_shamsalsadati@yahoo.com> wrote in message
news:hd9iks$knj$1@fred.mathworks.com...
> I have 4 vectors , three of them are each points coordinates(x,y,z) with
> 200,000 element each. The fourth vector (c) is the same size of other
> vectors. I want to have a 3d plot which x(i),y(i),z(i) specifies each
> point's location and c(i) would be the color correspond to each point. I
> tried scatter3 but it doesn't give me a good plot since my data locations
> are too close to each other inside the volume and also I want to have
> interpolation between the data. So, it would be a colorful cube which
> color in each point shows the related magnitude in "c" vector. I also
> tried "slice" command to have color faces in the cube but it doesn't plot
> it ,because my "c" is not a 3d matrix and is not specified as a function
> of coordinates and my coordinates are not specified by meshgrid and
> don’t have a specific trend, couldn’t use the patch, either
> (lots of data with no pattern). Could you
> please help me on how to do that and what are the options to have such a
> cube(having the magnitude inside the volume is preferred than just having
> it on its surface)?

Subject: How to plot a 3d color graph with a cloud of data?

From: sharmin

Date: 9 Nov, 2009 19:25:05

Message: 3 of 8

"Damian Sheehy" <Damian.Sheehy@mathworks.com> wrote in message <hd9o1j$1cf$1@fred.mathworks.com>...
> Hi Sharmin,
>
> You can convert your data into a mesh grid using scattered data
> interpolation.
>
> If you have release R2009a or later
> help TriScatteredInterp
>
> otherwise
> help griddata3
>
> Here's an example using TriScatteredInterp.
>
> % I will create sample data (x,y,z,v)
> x = 2*rand(5000,1)-1;
> y = 2*rand(5000,1)-1;
> z = 2*rand(5000,1)-1;
> v = x.^2 + y.^2 + z.^2;
>
> % Construct an interpolant from the sample data
> F = TriScatteredInterp(x,y,z,v)
>
>
> % Create a mesh grid and query the interpolant at those points
> d = -0.8:0.05:0.8;
> [xi,yi,zi] = meshgrid(d,d,d);
> vi = F(xi,yi,zi);
>
> You now have a regular grid defined by (xi,yi,zi,vi) which you can slice.
>
> Best regards,
>
> Damian
>
> "sharmin shamsalsadati" <sharmin_shamsalsadati@yahoo.com> wrote in message
> news:hd9iks$knj$1@fred.mathworks.com...
> > I have 4 vectors , three of them are each points coordinates(x,y,z) with
> > 200,000 element each. The fourth vector (c) is the same size of other
> > vectors. I want to have a 3d plot which x(i),y(i),z(i) specifies each
> > point's location and c(i) would be the color correspond to each point. I
> > tried scatter3 but it doesn't give me a good plot since my data locations
> > are too close to each other inside the volume and also I want to have
> > interpolation between the data. So, it would be a colorful cube which
> > color in each point shows the related magnitude in "c" vector. I also
> > tried "slice" command to have color faces in the cube but it doesn't plot
> > it ,because my "c" is not a 3d matrix and is not specified as a function
> > of coordinates and my coordinates are not specified by meshgrid and
> > don’t have a specific trend, couldn’t use the patch, either
> > (lots of data with no pattern). Could you
> > please help me on how to do that and what are the options to have such a
> > cube(having the magnitude inside the volume is preferred than just having
> > it on its surface)?
>

Subject: How to plot a 3d color graph with a cloud of data?

From: sharmin

Date: 9 Nov, 2009 19:27:02

Message: 4 of 8

Thank you for your response, but my problem is that my "c" value(or "v" in your example) is not a function of coordinates.It is a vector (200,000 by 1) same size of x,y,z . For instance, c(1) shows the magnitude(intensity) at (x(1) ,y(1),z(1)) and there are not dependent on each other.


"sharmin shamsalsadati" <sharmin_shamsalsadati@yahoo.com> wrote in message <hd9iks$knj$1@fred.mathworks.com>...
> I have 4 vectors , three of them are each points coordinates(x,y,z) with 200,000 element each. The fourth vector (c) is the same size of other vectors. I want to have a 3d plot which x(i),y(i),z(i) specifies each point's location and c(i) would be the color correspond to each point. I tried scatter3 but it doesn't give me a good plot since my data locations are too close to each other inside the volume and also I want to have interpolation between the data. So, it would be a colorful cube which color in each point shows the related magnitude in "c" vector. I also tried "slice" command to have color faces in the cube but it doesn't plot it ,because my "c" is not a 3d matrix and is not specified as a function of coordinates and my coordinates are not specified by meshgrid and don’t have a specific trend, couldn’t use the patch, either (lots of data with no pattern). Could
you
> please help me on how to do that and what are the options to have such a cube(having the magnitude inside the volume is preferred than just having it on its surface)?

Subject: How to plot a 3d color graph with a cloud of data?

From: Damian Sheehy

Date: 9 Nov, 2009 19:36:49

Message: 5 of 8

Hi Sharmin,

Unless I am missing something, I believe you are contradicting yourself. If
you say that c(i) is the intensity at x(i), y(i), z(i) then the intensity IS
a function of the coordinates.
In my example v(i) is the "value" at x(i), y(i), z(i) , same thing!

Regards,

Damian


"sharmin " <damian.sheehy@mathworks.com> wrote in message
news:hd9qe6$29c$1@fred.mathworks.com...
> Thank you for your response, but my problem is that my "c" value(or "v" in
> your example) is not a function of coordinates.It is a vector (200,000 by
> 1) same size of x,y,z . For instance, c(1) shows the magnitude(intensity)
> at (x(1) ,y(1),z(1)) and there are not dependent on each other.
>
>
> "sharmin shamsalsadati" <sharmin_shamsalsadati@yahoo.com> wrote in message
> <hd9iks$knj$1@fred.mathworks.com>...
>> I have 4 vectors , three of them are each points coordinates(x,y,z) with
>> 200,000 element each. The fourth vector (c) is the same size of other
>> vectors. I want to have a 3d plot which x(i),y(i),z(i) specifies each
>> point's location and c(i) would be the color correspond to each point. I
>> tried scatter3 but it doesn't give me a good plot since my data locations
>> are too close to each other inside the volume and also I want to have
>> interpolation between the data. So, it would be a colorful cube which
>> color in each point shows the related magnitude in "c" vector. I also
>> tried "slice" command to have color faces in the cube but it doesn't plot
>> it ,because my "c" is not a 3d matrix and is not specified as a function
>> of coordinates and my coordinates are not specified by meshgrid and
>> don’t have a specific trend, couldn’t use the patch, either
>> (lots of data with no pattern). Could
> you
>> please help me on how to do that and what are the options to have such a
>> cube(having the magnitude inside the volume is preferred than just having
>> it on its surface)?

Subject: How to plot a 3d color graph with a cloud of data?

From: sharmin shamsalsadati

Date: 12 Nov, 2009 15:48:01

Message: 6 of 8

I found a way to sort my data and consider the volume as a function of x,y,z.
My problem is that it gives me a monocolor plane. (It seemed to have the same problem of scatter3 when lots of data are used)I changed the interval in meshgrid and it didn't help! The code is attached here.

% t is the input file (214273 by 5)
for k=1:97
    for j=1:47
        for i=1:47
             x(k,j,i)=t(p,3);
             y(k,j,i)=t(p,4);
            z(k,j,i)=t(p,5);
             v(k,j,i)=t(p,1);
                        p=p+1;
        end
    end
 end
[X,Z,Y]=meshgrid(-705:10:675,-1455:10:475,-705:10:675);
  V=griddata3(x,z,y,v,X,Z,Y);
slice(X,Z,Y,V,-5,[],[]);

I appreciate your help.

"Damian Sheehy" <Damian.Sheehy@mathworks.com> wrote in message <hd9o1j$1cf$1@fred.mathworks.com>...
> Hi Sharmin,
>
> You can convert your data into a mesh grid using scattered data
> interpolation.
>
> If you have release R2009a or later
> help TriScatteredInterp
>
> otherwise
> help griddata3
>
> Here's an example using TriScatteredInterp.
>
> % I will create sample data (x,y,z,v)
> x = 2*rand(5000,1)-1;
> y = 2*rand(5000,1)-1;
> z = 2*rand(5000,1)-1;
> v = x.^2 + y.^2 + z.^2;
>
> % Construct an interpolant from the sample data
> F = TriScatteredInterp(x,y,z,v)
>
>
> % Create a mesh grid and query the interpolant at those points
> d = -0.8:0.05:0.8;
> [xi,yi,zi] = meshgrid(d,d,d);
> vi = F(xi,yi,zi);
>
> You now have a regular grid defined by (xi,yi,zi,vi) which you can slice.
>
> Best regards,
>
> Damian
>
> "sharmin shamsalsadati" <sharmin_shamsalsadati@yahoo.com> wrote in message
> news:hd9iks$knj$1@fred.mathworks.com...
> > I have 4 vectors , three of them are each points coordinates(x,y,z) with
> > 200,000 element each. The fourth vector (c) is the same size of other
> > vectors. I want to have a 3d plot which x(i),y(i),z(i) specifies each
> > point's location and c(i) would be the color correspond to each point. I
> > tried scatter3 but it doesn't give me a good plot since my data locations
> > are too close to each other inside the volume and also I want to have
> > interpolation between the data. So, it would be a colorful cube which
> > color in each point shows the related magnitude in "c" vector. I also
> > tried "slice" command to have color faces in the cube but it doesn't plot
> > it ,because my "c" is not a 3d matrix and is not specified as a function
> > of coordinates and my coordinates are not specified by meshgrid and
> > don’t have a specific trend, couldn’t use the patch, either
> > (lots of data with no pattern). Could you
> > please help me on how to do that and what are the options to have such a
> > cube(having the magnitude inside the volume is preferred than just having
> > it on its surface)?
>

Subject: How to plot a 3d color graph with a cloud of data?

From: Damian Sheehy

Date: 12 Nov, 2009 18:19:57

Message: 7 of 8

"sharmin shamsalsadati" <sharmin_shamsalsadati@yahoo.com> wrote in message
news:hdhanh$s11$1@fred.mathworks.com...
>I found a way to sort my data and consider the volume as a function of
>x,y,z.
> My problem is that it gives me a monocolor plane. (It seemed to have the
> same problem of scatter3 when lots of data are used)I changed the interval
> in meshgrid and it didn't help! The code is attached here.
>
> % t is the input file (214273 by 5)
> for k=1:97
> for j=1:47
> for i=1:47
> x(k,j,i)=t(p,3);
> y(k,j,i)=t(p,4);
> z(k,j,i)=t(p,5);
> v(k,j,i)=t(p,1);
> p=p+1;
> end
> end
> end
> [X,Z,Y]=meshgrid(-705:10:675,-1455:10:475,-705:10:675);
> V=griddata3(x,z,y,v,X,Z,Y);
> slice(X,Z,Y,V,-5,[],[]);
>
> I appreciate your help.
>

Sharmin,

That can mean one of two things;
(1) The intensity does not vary in the slice plane or
(2) If you expect the slice plane to show varying intensities, then you have
made a mistake somewhare

Your approach looks reasonable to me (Though I suspect you may be able make
your code run more efficiently by eliminating the three for loops and
vectorizing your code).
Why don't you try verifying your code using data sampled from an analyic
function.

For example, creste a test case like this for your code. That may pointpoint
where the problem is;

x = -2 + 4.*rand(10000,1);
y = -2 + 4.*rand(10000,1);
z = -2 + 4.*rand(10000,1);
v = x .* exp(-x.^2 - y.^2 - z.^2);

[xi,yi,zi] = meshgrid(-2:.2:2, -2:.25:2, -2:.16:2);
vi = griddata3(x,y,z,v,xi,yi,zi);
slice(xi,yi,zi,vi,[-1.2 .8 2],2,[-2 -.2])


Damian

Subject: How to plot a 3d color graph with a cloud of data?

From: Luigi Giaccari

Date: 17 Nov, 2009 20:28:03

Message: 8 of 8

"sharmin shamsalsadati" <sharmin_shamsalsadati@yahoo.com> wrote in message <hd9iks$knj$1@fred.mathworks.com>...
> I have 4 vectors , three of them are each points coordinates(x,y,z) with 200,000 element each. The fourth vector (c) is the same size of other vectors. I want to have a 3d plot which x(i),y(i),z(i) specifies each point's location and c(i) would be the color correspond to each point. I tried scatter3 but it doesn't give me a good plot since my data locations are too close to each other inside the volume and also I want to have interpolation between the data. So, it would be a colorful cube which color in each point shows the related magnitude in "c" vector. I also tried "slice" command to have color faces in the cube but it doesn't plot it ,because my "c" is not a 3d matrix and is not specified as a function of coordinates and my coordinates are not specified by meshgrid and don’t have a specific trend, couldn’t use the patch, either (lots of data with no pattern). Could
you
> please help me on how to do that and what are the options to have such a cube(having the magnitude inside the volume is preferred than just having it on its surface)?

I hope one of these work

Building the surface

http://www.advancedmcode.org/surface-recostruction-from-scattered-points-cloud-mycrustopen.html

http://www.advancedmcode.org/surface-recostruction-from-scattered-points-cloud-mycrust-robust.html

http://www.advancedmcode.org/how-to-plot-a-coloured-surface-from-3d-scatter.html
( this one shows how to colour it)

http://www.advancedmcode.org

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
color sharmin shamsalsadati 9 Nov, 2009 12:19:02
cube sharmin shamsalsadati 9 Nov, 2009 12:19:02
scatter data sharmin shamsalsadati 9 Nov, 2009 12:19:02
3d graph sharmin shamsalsadati 9 Nov, 2009 12:19:02
rssFeed for this Thread

Contact us at files@mathworks.com