MATLAB: I want x,y coordinates which are randomly generated between 1 to 300 ,condition is distance between every coordinate is >20. how to proceed further

homeworkrandom point placement

i=5 ; %% no. of random coordinates
xc = round((1 + (60-1)*rand(i,1)),0); %% random X- coordinates
yc = round((1 + (40-1)*rand(i,1)),0); %% random Y- coordinates
c = [xc,yc] ; %% storing random coordinates in a matrix
d = pdist(c); %% pdist finds distance between each and every coordinate (all possible distances)
z= squareform(d);%% it gives a 5*5 matrix containing distances
v = 500; %%
n = size(z,1);
z(1:(n+1):end) = v; %% replacing diagonal elements by some scalar because all diag elements wiil be zero
index = find(z<20) %% find which index number in matrix which are less than 20

Best Answer

How about the following?
BWremain = true(300);
% Number of random coordinates
N = 5;
% Selected coordinates are stored these variables
row = nan(N,1);
col = nan(N,1);
for kk = 1:N
BW = false(300);
p = find(BWremain);
p = p(randperm(numel(p),1));
BW(p) = true;
BW = bwdist(BW) > 20;
BWremain = BWremain & BW;
[row(kk),col(kk)] = ind2sub(size(BWremain),p);
end
Selected coordinates and circles (R = 20) around them looks like this.
selectedPoints.png