I want to create a grid what is saved in a matrix (nx3) (here: obsPos) with zeros in the third column. The grid should be uniformly spaced. The matrix should be defined by two vectors (dim: 3x1).
Objective: To create a mesh what is x meters long and y meters wide and save positions of this mesh into a matrix. This mesh should be evenly distributed, eg each mesh panel is one square meters big.
Cheers!
obsXlimit = 50; % Define size of the observer grid in x-direction (m)
obsYlimit = 20; % Define size of the observer grid in y-direction (m)
obsXspanVector = [obsXlimit 0];
obsYspanVector = [0 obsYlimit];
[obsX obsY] = meshgrid(obsXspanVector,obsYspanVector); % Generate X and Y data of the observer positions
obsZ = zeros(size(obsX, 1)); % Generate Z data of the observer positions (always with obsZ = 0)
obsPos = [obsX(:), obsY(:), obsZ(:)]; % Save every observer position
You state uniform grid, this is obtained using start:step:stop
with start
, step
and stop
being the point where the grid starts, the stepsize and where it ends respectively. As it seems, you have the grids as
obsXspanVector = [obsXlimit 0];
obsYspanVector = [0 obsYlimit];
Wich will make a grid only consisting of the start and endpoint. Additionally, as one square has to be 1 square meter big, I presume the stepsize should be one:
obsXspanVector = 0:1:obsXlimit;
obsYspanVector = 0:1:obsYlimit;
Then you can generate the grid for x and y with
[obsX obsY] = meshgrid(obsXspanVector,obsYspanVector);
Then to avoid forgetting, redefine the arrays obsX
and obsY
to be their Nx1 equivalent.
obsX = obsX(:);
obsY = obsY(:);
Then you can draw the zeros needed, though noticing that zeros
with 1 input makes a square matrix, and multiple inputs (possibly as array) give an array of the specified size
obsZ = zeros(size(obsX)); %size(obsX) = [N, 1]
and finally, you can merge
obsPos = [obsX(:), obsY(:), obsZ(:)];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.