[英]Use meshgrid with two different vectors
I want to create a grid what is saved in a matrix (nx3) (here: obsPos) with zeros in the third column. 我想创建一个网格,该网格保存在第三列中为零的矩阵(nx3)(此处为obsPos)中。 The grid should be uniformly spaced. 网格应均匀分布。 The matrix should be defined by two vectors (dim: 3x1). 矩阵应由两个向量定义(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. 目标:创建一个长x米,宽y米的网格并将该网格的位置保存到矩阵中。 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. 您声明统一的网格,这是使用start:step:stop
获得的,其中start
, step
和stop
分别是网格的起点,步长和终点。 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: 另外,由于一个正方形必须为1平方米大,因此我假定步长应该为1:
obsXspanVector = 0:1:obsXlimit;
obsYspanVector = 0:1:obsYlimit;
Then you can generate the grid for x and y with 然后您可以使用生成x和y的网格
[obsX obsY] = meshgrid(obsXspanVector,obsYspanVector);
Then to avoid forgetting, redefine the arrays obsX
and obsY
to be their Nx1 equivalent. 然后,为了避免忘记,请将数组obsX
和obsY
重新定义为其Nx1等效项。
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 然后您可以绘制所需的零点,但要注意,输入为1的zeros
构成一个方阵,而多个输入点(可能是数组)给出了指定大小的数组
obsZ = zeros(size(obsX)); %size(obsX) = [N, 1]
and finally, you can merge 最后,您可以合并
obsPos = [obsX(:), obsY(:), obsZ(:)];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.