Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

5 views
Skip to first unread message

sharmin shamsalsadati

unread,
Nov 9, 2009, 12:14:04 PM11/9/09
to
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)?

Damian Sheehy

unread,
Nov 9, 2009, 1:46:09 PM11/9/09
to
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_sh...@yahoo.com> wrote in message
news:hd9iks$knj$1...@fred.mathworks.com...

sharmin

unread,
Nov 9, 2009, 2:25:05 PM11/9/09
to
"Damian Sheehy" <Damian...@mathworks.com> wrote in message <hd9o1j$1cf$1...@fred.mathworks.com>...

sharmin

unread,
Nov 9, 2009, 2:27:02 PM11/9/09
to
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_sh...@yahoo.com> wrote in message <hd9iks$knj$1...@fred.mathworks.com>...

Damian Sheehy

unread,
Nov 9, 2009, 2:36:49 PM11/9/09
to
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...@mathworks.com> wrote in message
news:hd9qe6$29c$1...@fred.mathworks.com...

sharmin shamsalsadati

unread,
Nov 12, 2009, 10:48:01 AM11/12/09
to
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...@mathworks.com> wrote in message <hd9o1j$1cf$1...@fred.mathworks.com>...

Damian Sheehy

unread,
Nov 12, 2009, 1:19:57 PM11/12/09
to
"sharmin shamsalsadati" <sharmin_sh...@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


Luigi Giaccari

unread,
Nov 17, 2009, 3:28:03 PM11/17/09
to
"sharmin shamsalsadati" <sharmin_sh...@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&#8217;t have a specific trend, couldn&#8217;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

0 new messages