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
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
Best Answer