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

9 visualizaciones (últimos 30 días)
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 ?

Respuesta aceptada

Austin Thai
Austin Thai el 16 de Abr. de 2021
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);

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by