# I would like to create a set of random points with a distance separating them from each other. I would also like to create various sets of random numbers

1 view (last 30 days)
Akshay Kumar Pakala on 2 Nov 2021 For example i would like to create 50 random points that seprated by a distance of 20 from each other and another set of 27 random points that are seperated by a distance of 12 from each other. SImilarly, i would like to create a set of random for every bin of the histogram with the seperating distances respectively.
I am attaching the code that i used to generate the histogram
clc
clear all
[nr,nc,layers] = size(BW);
%% converting the image to 2d so the image can be labledd %%
if layers>1
BW = BW(:,:,1);
end
% end of lablling %%%%%%%%%%%%%%%%%
binaryimage = BW < 128;
bw = logical(binaryimage);
imwrite(bw, 'imagetoapp.jpg');
%% lablelling the image %%%%%%
[labeledimage, numberofblobs] = bwlabel(binaryimage,8);
props = regionprops(labeledimage, 'Equivdiameter');
x = numel(props);
y = zeros(x,1);
for i = 1:1:length(props)
y(i,1) = struct2array(props(i,1));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LAbled image to rgb
colouredimage = label2rgb(labeledimage,'jet', [0,0,0.5]);
coloredLabelsImage = label2rgb (labeledimage, 'jet', 'k', 'shuffle');
imshowpair(labeledimage,colouredimage,'montage')
hold on
%% generating histogram and curve fitting it using gaussian function%%%%%%%%%
figure()
y1 = histogram(y,45);
values = y1.Values;
a=y1.BinEdges;
for i = 1 : length(a)-1
b(i) = mean(a(i:i+1));
end
[barheights, position] = hist(y,45);
positiontranspose = position';
valuestranspose = values';
gauss = 'd + a*exp(-(1/2)*((x-b)/c)^2)'
startpoints = [40 20 10 0.5];
myfit = fit(positiontranspose,valuestranspose,gauss,'start',startpoints);
hold on
plot(myfit)
z(:,1) = myfit(x);
zt=myfit(b);
%% plot properties
xlabel('seperation distances')
ylabel('frequency')
hold on; plot(b, zt, 'r*')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% binary image
##### 2 CommentsShow 1 older commentHide 1 older comment
Akshay Kumar Pakala on 10 Nov 2021
Hey chris,
thanks for the repy.
for eq lets take bin 4 [8.81 11.08]. The avg diameter at bin 4 is 9.945. radius = 4.9725. Thus, i would like to create 16 points (frequency displayed in y axis of the histogram) which are randombly distributed in 3d space but are 4.9725 away from each other and other points aswell.