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

11 views (last 30 days)
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 ?

Accepted Answer

Austin Thai
Austin Thai on 16 Apr 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);

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!