3D Plot with line and dot
    6 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
Hi guys,
I'm new matlab user, i would to know if is possible to plot a cube using line and dot.
I have already plotted a cube with scatter3(x,y,z) and I like it, but I need also to link each point with a line. The problem is that if I add a line with 'plot edit' but when I rotate the graph or zoom in/out the lines dosen't adjust with the graph.
How can I do?
Thanks for you time.
Andrea
0 commentaires
Réponses (1)
  Doug Hull
      
 le 11 Mai 2012
        cornerX = [0 1 1 0 0 1 1 0];
cornerY = [0 0 1 1 0 0 1 1];
cornerZ = [0 0 0 0 1 1 1 1];
edges = [1 2;
         2 3;
         3 4;
         4 1;
         5 6;
         6 7;
         7 8;
         8 5;
         1 5;
         2 6;
         3 7
         4 8];
for i = 1:size(edges,1)
    line(cornerX(edges(i,:)), ...
         cornerY(edges(i,:)), ...
         cornerZ(edges(i,:)))
end
view(3)
xlim([-1 2]);
ylim([-1 2]);
zlim([-1 2]);
2 commentaires
  Julius
 le 9 Juin 2012
				Very nice! 
Would you know how to color the volume of the cube (not the edges) by some color?
(That color could represent a value from a color bar )
  Nathaniel
      
 le 9 Juin 2012
				Look at the help file for the _patch_ function, assuming that it's acceptable to color the faces, rather than the entire volume.
Voir également
Catégories
				En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!