Trippy
Trippy

Reputation: 213

Scatter plot for cube

I am looking for a way to visualise a cube using a scatter plot.

for example it is possible to do for a cylinder thus:

[X,Y,Z]=cylinder(20) 
x=X(:)
y=Y(:)
z=Z(:)
scatter3(x,y,z)

I'm unable to find something similar for cubes.

I hope to then 'fill' this cube by:

x=[0.5X(:);X(:)] 

and so on.

http://www.mathworks.com/matlabcentral/newsreader/view_thread/235581

I've looked at the above, however none of them will work for me I think. I need to also have a colour value attached to each data point to be plotted.

Upvotes: 1

Views: 1590

Answers (1)

Rash
Rash

Reputation: 4336

You can have the points inside the cube using meshgrid and then use scatter3,

figure
[X,Y,Z] = meshgrid(-1:.1:1); 
scatter3(X(:),Y(:),Z(:),3,'ob')
axis([-2 2 -2 2 -2 2])

enter image description here

Upvotes: 3

Related Questions