how i can generate random points inside a cube?

 채택된 답변

Wayne King
Wayne King 2012년 9월 25일
편집: Wayne King 2012년 9월 25일

0 개 추천

You can use rand()
Z = rand(10,10,10);
The above gives you the unit cube. You can translate this and scale the side length:
Z = 2+(4-2)*rand(10,10,10);

댓글 수: 1

Hi Wayne, I would understand
Z= rand(n,n,3);
which could be plotted using
plot3(Z(:,:,1),Z(:,:,2),Z(:,:,3),'k.')
Each point would then have 3 random coordinates. How would Z = rand(10,10,10) work and how would the coordinates be assigned?

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

추가 답변 (1개)

humaira akber
humaira akber 2013년 12월 15일

0 개 추천

npx=12; % no. of NPs on x-axis npy=12; % no. of NPs on y-axis npz=12;
dx=1; % distance b/w two NPs on x-axis dy=1; % distance b/w two NPs on y-axis dz=1;
x(1)=dx; % first particle is at dx from y-axis y(1)=dy; % first particle is at dx from x-axis z(1)=dz; np=0; x=zeros(1,npx); for k=1:npx x(k)=k*dx; y=zeros(1,npy); for l=1:npy y(l)=l*dy; z=zeros(1,npz); for m=1:npz z(m)=m*dz; end
end
end
np=npx*npy*npz
sir how to plot cube by using this assembly please give me answer as earlier as you can please.will be waiting

카테고리

도움말 센터File Exchange에서 Linear Algebra에 대해 자세히 알아보기

질문:

2012년 9월 25일

답변:

2013년 12월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by