So essentially I want a grid looking something like this:
0 0 0 0 0 00 1 0 0 1 00 0 0 0 0 00 1 0 0 1 00 0 0 0 0 0
or something similar, with flexibility in the number of ones and how they're distributed, and the size of the matrix.
This is what I currently have:
u = 1:500; % size of matrix
v = u;[u, v] = meshgrid(u, v);N_points = 5; %number of points in each axis
point_array = zeros(size(u));pos_x = round(size(u,1)/2) + separation_x * (-(N_points-1)/2:(N_points-1)/2); % positioning of points
pos_y = round(size(u,2)/2) + separation_y * (-(N_points-1)/2:(N_points-1)/2);[pos_x,pos_y] = meshgrid(pos_x,pos_y);point_array(sub2ind(size(point_array),pos_x,pos_y)) = 1; % converts x/y coordinates of chosen points into index of corresponding point in matrix, sets equal to 1.
Is there a more compact or straightforward way to achieve this?
Best Answer