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

5 Ansichten (letzte 30 Tage)
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 ?

Akzeptierte Antwort

Austin Thai
Austin Thai am 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);

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by