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

5 vues (au cours des 30 derniers jours)
Ben Worrall
Ben Worrall le 16 Avr 2021
Commenté : Ben Worrall le 17 Avr 2021
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 ?

Réponse acceptée

Austin Thai
Austin Thai le 16 Avr 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);

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by