Stuck making a Nx3 matrix where there are N rows of x,y,z coordinates

조회 수: 9 (최근 30일)
I want to create an 121x3 matrix of coordinates. The X and Y coordinates go in equal steps of 800 from 0 to 8000, the Z cooridnates are always at 100. Essentially its a square grid from 0 to 8000 in both the x and y direction at a heigh of 100, how would I do this ?

채택된 답변

Austin Thai
Austin Thai 2021년 4월 16일
If I am interpreting your question right, you want to vectorize three 11x11 grids of the coordinate directions to make a 121x3 matrix.
[Xgrid,Ygrid]=meshgrid(0:800:8000,0:800:8000);
Zgrid=100*ones(11,11);
x=reshape(Xgrid,[],1); % reshape x into a vector
y=reshape(Ygrid,[],1); % reshape y into a vector
z=reshape(Zgrid,[],1); % reshape z into a vector
XYZ=[x y z]; % Combine the vectors into a matrix
Alternatively, you can simply assign the grids in a 3D array before reshaping
[Xgrid,Ygrid]=meshgrid(0:800:8000,0:800:8000);
Zgrid=100*ones(11,11);
XYZ(:,:,1)=Xgrid;
XYZ(:,:,2)=Ygrid;
XYZ(:,:,3)=Zgrid;
XYZ=reshape(XYZ,121,3);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by