How to get the vertex points of all grid points within a cube?

조회 수: 7 (최근 30일)
Michael Ferguson
Michael Ferguson 2019년 7월 16일
답변: Bruno Luong 2019년 7월 16일
If I have a NxN cube, and wanted to plot a point at each integer x,y,z position included in the cube, how could I iterate through and store all the points to x,y,z point arrays?
  댓글 수: 2
Adam
Adam 2019년 7월 16일
What do you mean by 'I have a NxN cube'? In what format do you have it at the moment?
Michael Ferguson
Michael Ferguson 2019년 7월 16일
Sorry, obviously for 3D it would be NxNxN cube.

댓글을 달려면 로그인하십시오.

채택된 답변

Michael Ferguson
Michael Ferguson 2019년 7월 16일
It was a lot easier than I first realized, here was my solution to the problem after simply writing it out on paper and seeing a pattern. N=5
d1 = 0;
d2 = 0;
d3 = 0;
for k = 0:5
d1 = k;
for j = 0:5
d2 = j;
for i = 0:5
d3 = i;
scatter3(d1,d2,d3,0.5,'r'); hold on;
end
end
end
  댓글 수: 1
Adam
Adam 2019년 7월 16일
doc ndgrid
should be able to give you the points. It's advisable to plot them all as a single scatter plot, otherwise performance can suffer the more graphics objects you have and N^3 gets big pretty fast!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bruno Luong
Bruno Luong 2019년 7월 16일
[x,y,z]=ndgrid(0:5);
scatter3(x(:),y(:),z(:),'r')

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by